****TESTS FREE-RIDING USING THE SHARE OF A SUBJECT-GRADE THAT A TEACHER TEACHES AS THE MEASURE OF HOW MUCH OF AN AWARD THEY'RE RESPONSIBLE FOR***

  *OPEN STUDENT LEVEL FILE*
clear all
set mem 3g
set matsize 2000
set more off
cd "C:\teacher free riding\"

cap log close
log using teacher_share.log, replace
set seed 7563543



use "C:\teacher free riding\hisd_data_freeriding_b.dta", clear

sort campus year grade



**IDENTIFY THE MAXIMUM AWARD FOR A TEACHER
gen maxaward = 0
replace maxaward = 5000 if year == 2006 | year == 2007
replace maxaward = 7000 if year == 2008 | year == 2009

gen post = year >= 2006
drop if id == .
xtset id year

drop unit
gen unit = 1
egen enroll = sum(unit), by(campus year)
gen enroll2 = enroll^2
gen enroll3 = enroll^3
gen enroll4 = enroll^4

***NOTE THAT 9TH GRADE SCIENCE AND SOC ARE STANFORD RATHER THAN TAKS IN ASPIRE****
***FOR INITIAL ANALYSIS DO ONLY MATH & READING FOR ALL GRADES (TAKS) AND LANGUAGE FOR ALL GRADES (STANF)****
***SCIENCE & SOC FOR 10 & 11.FOR ACROSS DEPARTMENT ANALYSIS, LIMIT TO GRADES 10 & 11****


*ACHIEVEMENT LAGS
foreach subject in "math" "read" {
  gen ltaks_sd_scale_min_`subject' = l.taks_sd_scale_min_`subject'
 }
foreach subject in "math" "read" "lang" "socialstu" "science" {
  gen lstanford_sd_`subject'_scale = l.stanford_sd_`subject'_scale
 }

*NO SCIENCE & SOC IN 10TH GRADE SO USE 8TH GRADE LAG
foreach subject in "sci" "soc" {
  gen ltaks_sd_scale_min_`subject' = 0 if grade == 10 | grade == 11
  replace ltaks_sd_scale_min_`subject' = l.taks_sd_scale_min_`subject' if grade == 11
  gen l2taks_sd_scale_min_`subject' = 0 if grade == 10 | grade == 11
  replace l2taks_sd_scale_min_`subject' = l2.taks_sd_scale_min_`subject' if grade == 10
 }
 
 
 *GENERATE PRE-LAGS FROM 2004 - for 2004 and earlier use once lagged score
 foreach subject in "math" "read" {
 	gen taks_`subject'_2004 = l.taks_sd_scale_min_`subject'
	replace taks_`subject'_2004 = l2.taks_sd_scale_min_`subject' if year == 2006	
	replace taks_`subject'_2004 = l3.taks_sd_scale_min_`subject' if year == 2007
	replace taks_`subject'_2004 = l4.taks_sd_scale_min_`subject' if year == 2008
	replace taks_`subject'_2004 = l5.taks_sd_scale_min_`subject' if year == 2009
}

 foreach subject in "math" "read" "lang" "science" "socialstu" {
 	gen stanf_`subject'_2004 = l.stanford_sd_`subject'_scale
	replace stanf_`subject'_2004 = l2.stanford_sd_`subject'_scale if year == 2006
	replace stanf_`subject'_2004 = l3.stanford_sd_`subject'_scale if year == 2007
	replace stanf_`subject'_2004 = l4.stanford_sd_`subject'_scale if year == 2008
	replace stanf_`subject'_2004 = l5.stanford_sd_`subject'_scale if year == 2009
}

 *GENERATE PRE-LAGS FROM 2002 FOR ALL
 foreach subject in "math" "read" {
 	gen taks_`subject'_2002 = l.taks_sd_scale_min_`subject' if year == 2003
	replace taks_`subject'_2002 = l2.taks_sd_scale_min_`subject' if year == 2004
	replace taks_`subject'_2002 = l3.taks_sd_scale_min_`subject' if year == 2005
	replace taks_`subject'_2002 = l4.taks_sd_scale_min_`subject' if year == 2006
	replace taks_`subject'_2002 = l5.taks_sd_scale_min_`subject' if year == 2007
	replace taks_`subject'_2002 = l6.taks_sd_scale_min_`subject' if year == 2008
	replace taks_`subject'_2002 = l7.taks_sd_scale_min_`subject' if year == 2009
}
  

 foreach subject in "math" "read" "lang" "science" "socialstu" {
 	gen stanf_`subject'_2002 = l.stanford_sd_`subject'_scale if year == 2003
	replace stanf_`subject'_2002 = l2.stanford_sd_`subject'_scale if year == 2004
	replace stanf_`subject'_2002 = l3.stanford_sd_`subject'_scale if year == 2005
	replace stanf_`subject'_2002 = l4.stanford_sd_`subject'_scale if year == 2006
	replace stanf_`subject'_2002 = l5.stanford_sd_`subject'_scale if year == 2007
	replace stanf_`subject'_2002 = l6.stanford_sd_`subject'_scale if year == 2008
	replace stanf_`subject'_2002 = l7.stanford_sd_`subject'_scale if year == 2009
}


compress



***GENERATE MEASURE OF STUDENT MOBILITY
xtset id year
gen changeschools = l.campus != campus if grade >= 10 & year >= 2003 & l.campus != .
gen enterdistrict = l.campus == . if year >= 2003


*LIMIT TO 2003 AND LATER
keep if year >= 2003

*LIMIT TO GRADES 9 - 11
keep if grade >= 9 & grade <= 11
keep id campus year *taks_sd_scale_min* *stanford_sd_*_scale grade year ethnicity econdis atrisk speced lep gifted enroll* female taks_*_2004* stanf_*_2004* taks_*_2002* stanf_*_2002* changeschools enterdistrict
compress


*MERGE IN STUDENT-TEACHER LINKS
sort id campus year
merge 1:m id campus year using "C:\teacher free riding\secondary_classes.dta", keepusing(tch_number course_type course crs_title)
drop if _merge == 2


*ALLOW FOR DIFFERENT LAG VALUES BY GRADE & YEAR
foreach year of numlist 2003 2004 2007 2008 2009 {
 foreach grade of numlist 9/11 {
  foreach exam of varlist stanf_*_2004 taks_*_2004 stanf_*_2002 taks_*_2002{
    gen `exam'_y`year'_g`grade' = `exam'*(year == `year')*(grade == `grade')
  }
 }
}


*MERGE IN ASPIRE COURSE LISTS --> WORKS WELL FOR 2006-07 & LATER BUT POORLY FOR BEFORE SO WILL NEED TO USE OLD METHOD FOR PRE-PERIOD
drop _merge
sort course
merge course using "C:\teacher free riding\aspire_course_list_2009.dta", keep(subject)
replace subject = "" if year <= 2005
replace course_type = "" if year >= 2006
replace course_type = "eng" if subject == "Language Arts" & year >= 2006
replace course_type = "read" if subject == "Reading" & year >= 2006
replace course_type = "math" if subject == "Math" & year >= 2006
replace course_type = "sci" if subject == "Science" & year >= 2006
replace course_type = "soc" if subject == "Social Studies" & year >= 2006
drop if course_type == ""

gen course_type_a = course_type
replace course_type_a = "eng/read" if course_type == "eng"
replace course_type_a = "eng/read" if course_type == "read"

*MERGE IN TEACHER PREPS AND INDICATOR FOR BEING AN ASPIRE COURSE - LIMIT TO ASPIRE COURSES
sort tch_number campus year  crs_title
cap drop _merge
merge tch_number campus year  crs_title using "C:\teacher free riding\teacher_preps.dta", keep(aspire_course teacher_preps)
tab aspire_course, missing
keep if aspire_course == 1

***MERGE IN TEACHER PERCENTAGE DATA
sort campus year grade course_type_a tch_number
drop _merge
merge campus year grade course_type_a tch_number using "C:\teacher free riding\grade_percentages.dta"
drop if _merge == 2

*DROP TEACHERS WITH FEWER THAN 10 STUDENTS
drop if students < 10

*MERGE IN DEPARTMENT SIZE
drop _merge
sort campus year grade
merge campus year grade using "C:\teacher free riding\grade_departments.dta"
drop if _merge == 2

/*
***OPTION TO MERGE IN SCHOOL LEVEL PERCENTAGES AND DEPT SIZES FOR 2006-07
sort campus year course_type tch_number
drop _merge
replace share_students = . if year == 2006
merge m:1 campus year course_type tch_number using "C:\teacher free riding\school_percentages.dta", update keepusing(share_students)
drop if _merge == 2

sort campus year
drop _merge
merge campus year using "C:\teacher free riding\school_departments.dta"
drop if _merge == 2
foreach subject in "eng" "math" "read" "sci" "soc" {
   replace teachers_grade_`subject' = teachers_school_`subject' if year == 2006
}
*/

*MERGE IN TEACHER ID LINKED OVER TIME DERIVED FROM NAMES (CONDITIONAL ON BEING IN HISD IN 2006-07 OR LATER)
*NOTE THAT ONLY A SUBSET OF TEACHERS CAN BE LINKED BACK BEFORE 2006-07
destring tch_number, replace
drop _merge

**PRE -2006
save temp, replace
keep if year <= 2005
sort tch_number campus year 
merge m:1 tch_number campus year using teacher_linked_ids_pre
drop if _merge == 2
drop _merge
save temp1, replace

*POST - 2006
use temp, clear
keep if year >= 2006
sort tch_number
merge m:1 tch_number using teacher_linked_ids_post
drop if _merge == 2
drop _merge
append using temp1


*HISD HAD AN EXPERIMENTAL PROGRAM IN 2005-06 THAT WAS BASED ON INDIVIDUAL REWARDS, HENCE WE'LL DROP THIS YEAR
drop if year == 2005

*2006 IS BASED ON CAMPUS-WIDE DEPARTMENTAL AWARDS RATHER THAN GRADE LEVEL, SO DROP THIS YEAR TOO
drop if year == 2006

***ASSIGN WEIGHTS SO THAT EACH STUDENT HAS A VALUE OF 1 IN EACH SUBJECT
duplicates tag id year campus course_type, gen(classes_in_subject)
replace classes_in_subject = classes_in_subject + 1
gen weight = 1/classes_in_subject
drop if id == .



**GENERATE POST INDICATORS
gen post = year >= 2006
gen post_share_students = post*share_students
foreach var of varlist teachers_grade_* {
	gen post_`var' = post*`var'
}
gen school_year = campus*10000 + year

*GENERATE VARIABLES THAT POOL TAKS(10TH/11TH) AND STANFORD(9TH) FOR SCI AND SOC
	gen stanf_taks_soc = stanford_sd_socialstu_scale if grade == 9
	replace stanf_taks_soc = taks_sd_scale_min_soc if grade >= 10
	gen lstanford_sd_socialstu_scale_9 = lstanford_sd_socialstu_scale*(grade == 9)
	gen lstanford_sd_socialstu_scale_10 = lstanford_sd_socialstu_scale*(grade >= 10)


	gen stanf_taks_sci = stanford_sd_science_scale if grade == 9
	replace stanf_taks_sci = taks_sd_scale_min_sci if grade >= 10
	gen lstanford_sd_science_scale_9 = lstanford_sd_science_scale*(grade == 9)
	gen lstanford_sd_science_scale_10 = lstanford_sd_science_scale*(grade >= 10)
/*
*GENERATE PRE-ASPIRE TEACHER VALUE-ADDED
	xi i.grade*i.year, prefix(_g)
	xi i.female i.ethnicity i.econdis i.atrisk i.speced i.lep i.gifted 
	
	*MATH
	areg taks_sd_scale_min_math ltaks_sd_scale_min_math _I* _g* enroll* if regular_hs == 1  & course_type == "math" & (year == 2003 | year == 2004) [pw = weight], cluster(campus) absorb(campus)
	predict gain_math if (year == 2003 | year == 2004), resid
	egen pre_aspire_va_math = mean(gain_math), by(teacher_link_id)

	*ENGLISH
	areg stanford_sd_lang_scale lstanford_sd_lang_scale _I* _g* enroll* if regular_hs == 1  & course_type == "eng" & (year == 2003 | year == 2004) [pw = weight], cluster(campus) absorb(campus)
	predict gain_lang if (year == 2003 | year == 2004), resid
	egen pre_aspire_va_lang = mean(gain_lang), by(teacher_link_id)

	*SCIENCE
	areg stanf_taks_sci lstanford_sd_science_scale_9 lstanford_sd_science_scale_10 _I* _g* enroll* if regular_hs == 1  & course_type == "sci" & (year == 2003 | year == 2004) [pw = weight], cluster(campus) absorb(campus)
	predict gain_sci if (year == 2003 | year == 2004), resid
	egen pre_aspire_va_sci = mean(gain_sci), by(teacher_link_id)
	
	*SOCIAL STUDIES
	areg stanf_taks_soc lstanford_sd_socialstu_scale_9 lstanford_sd_socialstu_scale_10 _I* _g* enroll* if regular_hs == 1  & course_type == "soc" & (year == 2003 | year == 2004) [pw = weight], cluster(campus) absorb(campus)
	predict gain_soc if (year == 2003 | year == 2004), resid
	egen pre_aspire_va_soc = mean(gain_soc), by(teacher_link_id)
		
	*MATH-STANFORD
	areg stanford_sd_math_scale lstanford_sd_math_scale _I* _g* enroll* if regular_hs == 1  & course_type == "math" & (year == 2003 | year == 2004) [pw = weight], cluster(campus) absorb(campus)
	predict gain_math_stanf if (year == 2003 | year == 2004), resid
	egen pre_aspire_va_math_stanf = mean(gain_math_stanf), by(teacher_link_id)
			
	
save temp_b, replace
*/

*DROP TEACHERS WHO HAVE MORE THAN 90% SPECIAL EDUCATION or LEPSTUDENTS
	egen spec_ed_share = mean(speced), by(tch_number campus grade year subject)
	egen lep_share = mean(lep), by(tch_number campus grade year subject)
	drop if spec_ed_share > .8
	drop if lep_share > .8
	
keep if grade >= 9 & grade <= 11


*MERGE IN PEER CHARACTERISTICS
sort id year grade campus course_type tch_number
merge m:1 id year grade campus course_type tch_number using peer_characteristics.dta


cap rm teachers_share_pooled.txt
cap rm teachers_share_pooled.xml


save temp, replace



**GENERATE DATASET OF LAGGED SHARES

	*MATH
	use temp, clear
	keep if course_type == "math"
	collapse (mean) share_students post_share_students [aw = weight], by(id year)
	xtset id year
	gen lshare_students = l.share_students
	gen lpost_share_students = l.post_share_students
	gen l2share_students = l2.share_students
	gen l2post_share_students = l2.post_share_students	
	save math_persist.dta, replace
	
	*ENGLISH
	use temp, clear
	keep if course_type == "eng"
	collapse (mean) share_students post_share_students [aw = weight], by(id year)
	xtset id year
	gen lshare_students = l.share_students
	gen lpost_share_students = l.post_share_students
	gen l2share_students = l2.share_students
	gen l2post_share_students = l2.post_share_students	
	save eng_persist.dta, replace
	
	*SCIENCE
	use temp, clear
	keep if course_type == "sci"
	collapse (mean) share_students post_share_students [aw = weight], by(id year)
	xtset id year
	gen lshare_students = l.share_students
	gen lpost_share_students = l.post_share_students
	gen l2share_students = l2.share_students
	gen l2post_share_students = l2.post_share_students	
	save sci_persist.dta, replace

	*SOCIOLOGY
	use temp, clear
	keep if course_type == "soc"
	collapse (mean) share_students post_share_students [aw = weight], by(id year)
	xtset id year
	gen lshare_students = l.share_students
	gen lpost_share_students = l.post_share_students
	gen l2share_students = l2.share_students
	gen l2post_share_students = l2.post_share_students	
	save soc_persist.dta, replace
	


use temp, clear

*CONDUCT ANOVA
xi i.grade*i.year, prefix(_g)
xi i.female i.ethnicity i.econdis i.atrisk i.speced i.lep i.gifted 
xi i.school_year, prefix(_c)	

*MATH
loneway share_students teacher_newid if year >= 2006 & regular_hs == 1 & course_type == "math" & stanf_math_2004 != . [aw = weight]
reg share_students stanf_math_2004_y*_g*  _I* _g* enroll* if regular_hs == 1 & course_type == "math" & year >=2006 [pw = weight] 
predict residual_math, resid
loneway residual_math teacher_newid if year >= 2006 & regular_hs == 1 & course_type == "math" & stanf_math_2004 != . [aw = weight]
reg share_students stanf_math_2004_y*_g*  _I* _g* enroll* _c* if regular_hs == 1 & course_type == "math" & year >=2006 [pw = weight] 
predict residual_math_fe, resid
loneway residual_math_fe teacher_newid if year >= 2006 & regular_hs == 1 & course_type == "math" & stanf_math_2004 != . [aw = weight]

*English
loneway share_students teacher_newid if year >= 2006 & regular_hs == 1 & course_type == "eng" & stanf_lang_2004 != . [aw = weight]
reg share_students stanf_lang_2004_y*_g*  _I* _g* enroll* if regular_hs == 1 & course_type == "eng" & year >=2006 [pw = weight]
predict residual_eng, resid
loneway residual_eng teacher_newid if year >= 2006 & regular_hs == 1 & course_type == "eng" & stanf_lang_2004 != . [aw = weight]
reg share_students stanf_lang_2004_y*_g*  _I* _g* enroll* _c* if regular_hs == 1 & course_type == "eng" & year >=2006 [pw = weight]
predict residual_eng_fe, resid
loneway residual_eng_fe teacher_newid if year >= 2006 & regular_hs == 1 & course_type == "eng" & stanf_lang_2004 != . [aw = weight]

*Science
loneway share_students teacher_newid if year >= 2006 & regular_hs == 1 & course_type == "sci" & stanf_science_2004 != . [aw = weight]
reg share_students stanf_science_2004_y*_g*  _I* _g* enroll* if regular_hs == 1 & course_type == "sci" & year >=2006 [pw = weight]
predict residual_sci, resid
loneway residual_sci teacher_newid if year >= 2006 & regular_hs == 1 & course_type == "sci" & stanf_science_2004 != . [aw = weight]
reg share_students stanf_science_2004_y*_g*  _I* _g* enroll* _c* if regular_hs == 1 & course_type == "sci" & year >=2006 [pw = weight]
predict residual_sci_fe, resid
loneway residual_sci_fe teacher_newid if year >= 2006 & regular_hs == 1 & course_type == "sci" & stanf_science_2004 != . [aw = weight]

*Socialstu
loneway share_students teacher_newid if year >= 2006 & regular_hs == 1 & course_type == "soc" & stanf_socialstu_2004 != . [aw = weight]
reg share_students stanf_socialstu_2004_y*_g*  _I* _g* enroll* if regular_hs == 1 & course_type == "soc" & year >=2006 [pw = weight]
predict residual_soc, resid
loneway residual_soc teacher_newid if year >= 2006 & regular_hs == 1 & course_type == "soc" & stanf_socialstu_2004 != .  [aw = weight]
reg share_students stanf_socialstu_2004_y*_g*  _I* _g* _c* enroll* if regular_hs == 1 & course_type == "soc" & year >=2006 [pw = weight]
predict residual_soc_fe, resid
loneway residual_soc_fe teacher_newid if year >= 2006 & regular_hs == 1 & course_type == "soc" & stanf_socialstu_2004 != .  [aw = weight]


***BASIC LINEAR MODEL**
	xi i.grade*i.year, prefix(_g)
	xi i.female i.ethnicity i.econdis i.atrisk i.speced i.lep i.gifted 

	***MATH --> TAKS MATH
	**NO CONTROLS EXCEPT GRADE-YEAR INDICATORS - LIMIT TO STUDENTS WHO HAVE A LAGGED SCORE
	reg taks_sd_scale_min_math post_share_students share_students post _g* enroll* if taks_math_2004 !=. & regular_hs == 1 & course_type == "math" [pw = weight], cluster(campus)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Math, No Controls")
	
	**INCLUDE LAG FOR GROWTH MODEL
	reg taks_sd_scale_min_math post_share_students share_students post taks_math_2004_y*_g* _g* enroll* if regular_hs == 1 & course_type == "math" [pw = weight], cluster(campus)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Math, Lag Test")

	**ADD CONTROLS
	reg taks_sd_scale_min_math post_share_students share_students post taks_math_2004_y*_g* _I* _g* enroll* if regular_hs == 1 & course_type == "math" [pw = weight], cluster(campus)
  	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Math, Controls")

	**ADD School-Year FE
	areg taks_sd_scale_min_math post_share_students share_students post taks_math_2004_y*_g* _I* _g* enroll* if regular_hs == 1 & course_type == "math" [pw = weight], cluster(campus) absorb(campus)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Math, School FE")
	
	***SCHOOL-YEAR FE
	areg taks_sd_scale_min_math post_share_students share_students post taks_math_2004_y*_g* _I* _g* enroll* if regular_hs == 1 & course_type == "math" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Math, School-Year FE")
    
  
	***ENGLISH --> STANFORD LANGUAGE***

	**NO CONTROLS - LIMIT TO STUDENTS WHO HAVE A LAGGED SCORE
	reg stanford_sd_lang_scale  post_share_students share_students post _g* enroll* if stanf_lang_2004 !=. & regular_hs == 1 & course_type == "eng" [pw = weight], cluster(campus)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, No Controls")

	**INCLUDE LAG FOR GROWTH MODEL
	reg stanford_sd_lang_scale  post_share_students share_students  post  stanf_lang_2004_y*_g* _g* enroll* if regular_hs == 1 & course_type == "eng" [pw = weight], cluster(campus)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, Lag Test")

	**ADD CONTROLS
	reg stanford_sd_lang_scale  post_share_students share_students  post  stanf_lang_2004_y*_g* _I* _g* enroll* if regular_hs == 1 & course_type == "eng" [pw = weight], cluster(campus)
  	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, Controls")

	**ADD SCHOOL FE
	areg stanford_sd_lang_scale  post_share_students share_students  post  stanf_lang_2004_y*_g* _I* _g* enroll* if regular_hs == 1 & course_type == "eng" [pw = weight], cluster(campus) absorb(campus)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, School FE")
	
	***SCHOOL-YEAR FE
	areg stanford_sd_lang_scale  post_share_students share_students  post  stanf_lang_2004_y*_g* _I* _g* enroll* if regular_hs == 1 & course_type == "eng" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, School-Year FE")

 
  
	***	SCIENCE POOLED

	
	**NO CONTROLS - LIMIT TO STUDENTS WHO HAVE A LAGGED SCORE
	reg stanf_taks_sci  post_share_students share_students post  _g* enroll* if stanf_science_2004 != . & regular_hs == 1  & course_type == "sci" [pw = weight], cluster(campus)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, No Controls")

	**INCLUDE LAG FOR GROWTH MODEL
	reg  stanf_taks_sci  post_share_students share_students  post  stanf_science_2004_y*_g* _g* enroll* if  regular_hs == 1 & course_type == "sci" [pw = weight], cluster(campus)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, Lag Test")

	**ADD CONTROLS
	reg  stanf_taks_sci  post_share_students share_students  post stanf_science_2004_y*_g*  _I* _g* enroll* if  regular_hs == 1 &  course_type == "sci" [pw = weight], cluster(campus)
  	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, Controls")

	**ADD SCHOOL FE
	areg  stanf_taks_sci  post_share_students share_students  post stanf_science_2004_y*_g*  _I* _g* enroll* if  regular_hs == 1 &  course_type == "sci" [pw = weight], cluster(campus) absorb(campus)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, School FE")

	*SCHOOL-YEAR FE
	areg  stanf_taks_sci  post_share_students share_students  post stanf_science_2004_y*_g*  _I* _g* enroll* if regular_hs == 1 & course_type == "sci" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, School-Year FE")


  
	***SOC POOLED

	**NO CONTROLS - LIMIT TO STUDENTS WHO HAVE A LAGGED SCORE
	reg stanf_taks_soc  post_share_students share_students post _g* enroll* if  stanf_socialstu_2004 != . & regular_hs == 1  & course_type == "soc" [pw = weight], cluster(campus)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, No Controls")

	**INCLUDE LAG FOR GROWTH MODEL
	reg  stanf_taks_soc   post_share_students share_students post  stanf_socialstu_2004_y*_g* _g* enroll* if  regular_hs == 1  & course_type == "soc" [pw = weight], cluster(campus)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, Lag Test")

	**ADD CONTROLS
	reg  stanf_taks_soc  post_share_students share_students post stanf_socialstu_2004_y*_g*  _I* _g* enroll* if  regular_hs == 1  & course_type == "soc" [pw = weight], cluster(campus)
  	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, Controls")

	**ADD SCHOOL FE
	areg  stanf_taks_soc post_share_students share_students post stanf_socialstu_2004_y*_g*  _I* _g* enroll* if  regular_hs == 1  & course_type == "soc" [pw = weight], cluster(campus) absorb(campus)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, School FE")

	**SCHOOL-YEAR FE
	areg  stanf_taks_soc post_share_students share_students post stanf_socialstu_2004_y*_g*  _I* _g* enroll* if  regular_hs == 1  & course_type == "soc" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, School-Year")
  	

	
	*MATH - STANFORD MATH
	
	**NO CONTROLS EXCEPT GRADE-YEAR INDICATORS - LIMIT TO STUDENTS WHO HAVE A LAGGED SCORE
	reg stanford_sd_math_scale post_share_students share_students post _g* enroll* if stanf_math_2004 !=. & regular_hs == 1 & course_type == "math" [pw = weight], cluster(campus)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Math - Stanf, No Controls")
	
	**INCLUDE LAG FOR GROWTH MODEL
	reg stanford_sd_math_scale post_share_students share_students post stanf_math_2004_y*_g* _g* enroll* if regular_hs == 1 & course_type == "math" [pw = weight], cluster(campus)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Math - Stanf, Lag Test")

	**ADD CONTROLS
	reg stanford_sd_math_scale post_share_students share_students post stanf_math_2004_y*_g*  _I* _g* enroll* if regular_hs == 1 & course_type == "math" [pw = weight], cluster(campus)
  	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Math - Stanf, Controls")

	**ADD SCHOOL FE
	areg stanford_sd_math_scale post_share_students share_students post stanf_math_2004_y*_g*  _I* _g* enroll* if regular_hs == 1 & course_type == "math" [pw = weight], cluster(campus) absorb(campus)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Math - Stanf, School FE")
	
	***SCHOOL-YEAR FE
	areg stanford_sd_math_scale post_share_students share_students post stanf_math_2004_y*_g*  _I* _g* enroll* if regular_hs == 1 & course_type == "math" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Math - Stanf, School-Year FE")
	reg stanford_sd_math_scale post_share_students share_students post stanf_math_2004_y*_g*  _I* _g* enroll* if  regular_hs == 1 & course_type == "math" [pw = weight]

	


*USE QUADRATIC IN SHARE
gen share_students_2 = share_students^2
gen post_share_students_2 = post*share_students^2

	
	xi i.grade*i.year, prefix(_g)
	xi i.female i.ethnicity i.econdis i.atrisk i.speced i.lep i.gifted
	
	
	***MATH --> TAKS MATH
	areg taks_sd_scale_min_math post_share_students post_share_students_2 share_students share_students_2 post taks_math_2004_y*_g* _I* _g* enroll* if  regular_hs == 1 & course_type == "math" [pw= weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students post_share_students_2 share_students share_students_2 using teachers_share_pooled, excel dec(3) nocons ctitle("Math, School FE, quadratic")
    
	***ENGLISH --> STANFORD LANGUAGE***
	areg stanford_sd_lang_scale  post_share_students post_share_students_2 share_students share_students_2  post  stanf_lang_2004_y*_g* _I* _g* enroll* if   regular_hs == 1 & course_type == "eng" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students post_share_students_2 share_students share_students_2 using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, School FE, quadratic")

	***SCIENCE - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	areg  stanf_taks_sci  post_share_students post_share_students_2 share_students share_students_2  post stanf_science_2004_y*_g*  _I* _g* enroll* if regular_hs == 1  & course_type == "sci" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students post_share_students_2 share_students share_students_2 using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, School FE, quadratic")
	
	*SOC
	areg  stanf_taks_soc post_share_students post_share_students_2 share_students share_students_2 post stanf_socialstu_2004_y*_g*  _I* _g* enroll* if   regular_hs == 1  & course_type == "soc" [pw  = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students post_share_students_2 share_students share_students_2 using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, School FE, quadratic")
 	
	***MATH - STANF
	areg stanford_sd_math_scale post_share_students post_share_students_2 share_students share_students_2 post stanf_math_2004_y*_g*  _I* _g* enroll* if   regular_hs == 1 & course_type == "math" [pw  = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students post_share_students_2 share_students share_students_2 using teachers_share_pooled, excel dec(3) nocons ctitle("Math - Stanf, School FE, quadratic")
   

	

***USE VARIATION IN MONETARY AWARD AMOUNT PER SUBJECT BASED ON AWARD IN GIVEN YEAR AND NUMBER OF SUBJECTS TAUGHT

	*SINCE IT IS UNCLEAR HOW HAVING MORE THAN 2 SUBJECTS IS DEALT WITH AFTER 2006 (AND MORE THAN 3 DURING 2006) DROP ANY TEACHER WITH MORE THAN 2 SUBJECTS
	drop if subjects_taught > 2
	
	**I'M IGNORING THE ATTENDANCE BONUS... MAY WANT TO DO A SPEC CHECK THAT INCORPORATES IT

	gen award =	0
	replace award = 5 if year == 2006 & subjects_taught == 1
	replace award = 2.5 if year == 2006 & subjects_taught == 2
	replace award = 1.667 if year == 2007 & subjects_taught == 1
	replace award = 0.833 if year == 2007 & subjects_taught == 2
	replace award = 2.333 if year == 2008 & subjects_taught == 1
	replace award = 1.167 if year == 2008 & subjects_taught == 2
	replace award = 2.333 if year == 2009 & subjects_taught == 1
	replace award = 1.167 if year == 2009 & subjects_taught == 2

	gen award_share_students = award*share_students
	
	
	***MATH --> TAKS MATH
	areg taks_sd_scale_min_math award_share_students share_students  award  taks_math_2004_y*_g* _I* _g* enroll* if regular_hs == 1 & course_type == "math" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 award_share_students share_students  award  using teachers_share_pooled, excel dec(3) nocons ctitle("Math, School FE, Award Amount")

	***ENGLISH --> STANFORD LANGUAGE***
	areg stanford_sd_lang_scale  award_share_students share_students award      stanf_lang_2004_y*_g* _I* _g* enroll* if regular_hs == 1 & course_type == "eng" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 award_share_students share_students award   using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, School FE, Award Amount")

	***SCIENCE  - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	areg  stanf_taks_sci  award_share_students share_students award  stanf_science_2004_y*_g*    _I* _g* enroll* if lstanford_sd_science_scale & regular_hs == 1  & course_type == "sci" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 award_share_students share_students award   using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, School FE, Award Amount")

	***SOC
	areg  stanf_taks_soc award_share_students share_students award    stanf_socialstu_2004_y*_g*  _I* _g* enroll* if  regular_hs == 1  & course_type == "soc" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 award_share_students share_students award   using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, School FE, Award Amount")

	***MATH - STANF
	areg stanford_sd_math_scale award_share_students share_students award stanf_math_2004_y*_g*  _I* _g* enroll* if regular_hs == 1 & course_type == "math" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 award_share_students share_students award using teachers_share_pooled, excel dec(3) nocons ctitle("Math - Stanf, School FE, Award Amount")

	
*INCLUDE BOTH DEPARTMENT SIZE AND SHARE OF STUDENTS IN REGRESSION --> SEE IF THE SHARE ESTIMATES HOLD FOR DEPARTMENTS OF SAME SIZE WITH DIFFERENT DISTRIBUTIONS
*CAN ONLY USE SCHOOL FE TO ENSURE ENOUGH VARIATION IN DEPARTMENT SIZE
	use temp, clear
	xi i.grade*i.year, prefix(_g)
	xi i.female i.ethnicity i.econdis i.atrisk i.speced i.lep i.gifted 
	
	gen teachers_grade = .
	replace teachers_grade = teachers_grade_math if course_type == "math"
	replace teachers_grade = teachers_grade_eng if course_type == "eng"
	replace teachers_grade = teachers_grade_sci if course_type == "sci"
	replace teachers_grade = teachers_grade_soc if course_type == "soc"
	replace teachers_grade = teachers_grade_read if course_type == "read"
	
	gen post_teachers_grade = post*teachers_grade

	***MATH --> TAKS MATH
	areg taks_sd_scale_min_math post_share_students post_teachers_grade share_students teachers_grade post taks_math_2004_y*_g* _I* _g* enroll* if regular_hs == 1 & course_type == "math" [pw = weight], cluster(campus) absorb(campus)
	outreg2 post_share_students post_teachers_grade share_students teachers_grade using teachers_share_pooled, excel dec(3) nocons ctitle("Math, School FE, Share & Dept Size")

	***ENGLISH --> STANFORD LANGUAGE***
	areg stanford_sd_lang_scale  post_share_students post_teachers_grade share_students teachers_grade  post  stanf_lang_2004_y*_g* _I* _g* enroll* if regular_hs == 1 & course_type == "eng" [pw = weight], cluster(campus) absorb(campus)
	outreg2 post_share_students post_teachers_grade share_students teachers_grade using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, School FE, Share & Dept Size")

	***SCIENCE - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	areg  stanf_taks_sci  post_share_students post_teachers_grade share_students teachers_grade  post stanf_science_2004_y*_g* _I* _g* enroll* if  regular_hs == 1  & course_type == "sci" [pw = weight], cluster(campus) absorb(campus)
	outreg2 post_share_students post_teachers_grade share_students teachers_grade using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, School FE, Share & Dept Size")

	***SOC
	areg  stanf_taks_soc post_share_students post_teachers_grade share_students teachers_grade post stanf_socialstu_2004_y*_g*  _I* _g* enroll* if  regular_hs == 1  & course_type == "soc" [pw = weight], cluster(campus) absorb(campus)
	outreg2 post_share_students post_teachers_grade share_students teachers_grade using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, School FE, Share & Dept Size")
	
	***MATH - STANF
	areg stanford_sd_math_scale post_share_students post_teachers_grade share_students teachers_grade _I* _g* enroll*  stanf_math_2004_y*_g*  if regular_hs == 1 & course_type == "math" [pw = weight], cluster(campus) absorb(campus)
	outreg2 post_share_students post_teachers_grade share_students teachers_grade using teachers_share_pooled, excel dec(3) nocons ctitle("Math - Stanf, School FE, , Share & Dept Size")
 

*ADD SCHOOL-GRADE FE
xi i.grade*i.year, prefix(_g)
xi i.campus*i.grade, prefix(_c)
xi i.female i.ethnicity i.econdis i.atrisk i.speced i.lep i.gifted 
	
 
	**MATH
	areg taks_sd_scale_min_math post_share_students share_students post taks_math_2004_y*_g* _I* _g* _c* enroll* if regular_hs == 1 & course_type == "math" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Math, School-Grade & School-Year FE, All")

	***ENGLISH --> STANFORD LANGUAGE***
	areg stanford_sd_lang_scale  post_share_students share_students  post  stanf_lang_2004_y*_g* _I* _g* _c* enroll* if regular_hs == 1 & course_type == "eng" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, School-Grade & School-Year FE, All")


	***SCIENCE - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	areg  stanf_taks_sci  post_share_students share_students  post stanf_science_2004_y*_g* _I* _g* _c* enroll* if regular_hs == 1  & course_type == "sci" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, School-Grade & School-Year FE, All")

	***SOC
	areg  stanf_taks_soc post_share_students share_students post stanf_socialstu_2004_y*_g* _I* _g* _c* enroll* if lstanford_sd_socialstu_scale & regular_hs == 1  & course_type == "soc" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, School-Grade & School-Year FE, All")
	

	***MATH - STANF
	areg stanford_sd_math_scale post_share_students share_students post _I* _g* _c* enroll* stanf_math_2004_y*_g*  if regular_hs == 1 & course_type == "math" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Math - Stanf, School-Grade & School-Year FE, All")
	

*USE 2002-03 SCORES FOR LAG FOR ALL GRADE/YEARS
xi i.grade*i.year, prefix(_g)
xi i.female i.ethnicity i.econdis i.atrisk i.speced i.lep i.gifted 
	
 
	**MATH
	areg taks_sd_scale_min_math post_share_students share_students post taks_math_2002_y*_g* _I* _g* enroll* if regular_hs == 1 & course_type == "math" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Math, 2002 Lag, All")

	***ENGLISH --> STANFORD LANGUAGE***
	areg stanford_sd_lang_scale  post_share_students share_students  post  stanf_lang_2002_y*_g* _I* _g* enroll* if regular_hs == 1 & course_type == "eng" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, 2002 Lag, All")


	***SCIENCE - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	areg  stanf_taks_sci  post_share_students share_students  post stanf_science_2002_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "sci" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, 2002 Lag, All")

	***SOC
	areg  stanf_taks_soc post_share_students share_students post stanf_socialstu_2002_y*_g* _I* _g* enroll* if lstanford_sd_socialstu_scale & regular_hs == 1  & course_type == "soc" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, 2002 Lag, All")
	

	***MATH - STANF
	areg stanford_sd_math_scale post_share_students share_students post _I* _g* enroll* stanf_math_2002_y*_g*  if regular_hs == 1 & course_type == "math" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Math - Stanf, 2002 Lag, All")
	



*USE PRIOR YEAR LAG W/O GRADE-YEAR INTERACTIONS
xi i.grade*i.year, prefix(_g)
xi i.female i.ethnicity i.econdis i.atrisk i.speced i.lep i.gifted 
	
 
	**MATH
	areg taks_sd_scale_min_math post_share_students share_students post ltaks_sd_scale_min_math _I* _g* enroll* if regular_hs == 1 & course_type == "math" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Math, 1yr Lag, All")

	***ENGLISH --> STANFORD LANGUAGE***
	areg stanford_sd_lang_scale  post_share_students share_students  post  lstanford_sd_lang_scale _I* _g* enroll* if regular_hs == 1 & course_type == "eng" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, 1yr Lag, All")


	***SCIENCE - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	areg  stanf_taks_sci  post_share_students share_students  post lstanford_sd_science_scale_9 lstanford_sd_science_scale_10 _I* _g* enroll* if regular_hs == 1  & course_type == "sci" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, 1yr Lag, All")

	***SOC
	areg  stanf_taks_soc post_share_students share_students post lstanford_sd_socialstu_scale_9 lstanford_sd_socialstu_scale_10 _I* _g* enroll* if lstanford_sd_socialstu_scale & regular_hs == 1  & course_type == "soc" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, 1yr Lag, All")
	



*ADDING TEACHER FIXED EFFECTS

	save temp, replace
	keep if teacher_link_id != .

	xi i.grade*i.year, prefix(_g)
	xi i.campus, prefix(_c)
	xi i.female i.ethnicity i.econdis i.atrisk i.speced i.lep i.gifted 
	
  
	**MATH
	areg taks_sd_scale_min_math post_share_students share_students post taks_math_2004_y*_g* _I* _g* enroll* if regular_hs == 1 & course_type == "math" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Math, School FE, Teacher FE Sample, All")

	areg taks_sd_scale_min_math post_share_students share_students post taks_math_2004_y*_g* _I* _g* _c* enroll* if regular_hs == 1 & course_type == "math" [pw = weight], cluster(campus) absorb(teacher_link_id)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Math, School & Teacher FE, Teacher FE Sample, All")

	***ENGLISH --> STANFORD LANGUAGE***
	areg stanford_sd_lang_scale  post_share_students share_students  post  stanf_lang_2004_y*_g* _I* _g* enroll* if regular_hs == 1 & course_type == "eng" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, School FE, Teacher FE Sample, All")

  	areg stanford_sd_lang_scale  post_share_students share_students  post  stanf_lang_2004_y*_g* _I* _g* _c* enroll* if regular_hs == 1 & course_type == "eng" [pw = weight], cluster(campus) absorb(teacher_link_id)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, School & Teacher FE, Teacher FE Sample, All")

	***SCIENCE - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	areg  stanf_taks_sci  post_share_students share_students  post stanf_science_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "sci" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, School FE, Teacher FE Sample, All")

  	areg  stanf_taks_sci  post_share_students share_students  post stanf_science_2004_y*_g*  _I* _g* _c* enroll* if  regular_hs == 1  & course_type == "sci" [pw = weight], cluster(campus) absorb(teacher_link_id)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, School & Teacher FE, Teacher FE Sample, All")

	***SOC
	areg  stanf_taks_soc post_share_students share_students post stanf_socialstu_2004_y*_g* _I* _g* enroll* if lstanford_sd_socialstu_scale & regular_hs == 1  & course_type == "soc" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, School FE, Teacher FE Sample, All")
	
	areg  stanf_taks_soc post_share_students share_students post stanf_socialstu_2004_y*_g*  _I* _g* _c* enroll* if lstanford_sd_socialstu_scale & regular_hs == 1  & course_type == "soc" [pw = weight], cluster(campus) absorb(teacher_link_id)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, School & Teacher FE, Teacher FE Sample, All")
	

	***MATH - STANF
	areg stanford_sd_math_scale post_share_students share_students post _I* _g* enroll* stanf_math_2004_y*_g*  if regular_hs == 1 & course_type == "math" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Math - Stanf, School FE,  Teacher FE Sample, All")
	
	areg stanford_sd_math_scale post_share_students share_students post _I* _g* _c* enroll* stanf_math_2004_y*_g*  if regular_hs == 1 & course_type == "math" [pw = weight], cluster(campus) absorb(teacher_link_id)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Math - Stanf, School & Teacher FE,  Teacher FE Sample, All")
    

	
*CONTROL FOR STUDENT NUMBERS
	use temp, clear
	xi i.grade*i.year, prefix(_g)
	xi i.female i.ethnicity i.econdis i.atrisk i.speced i.lep i.gifted 

	***MATH --> TAKS MATH
	areg taks_sd_scale_min_math post_share_students  share_students  students post taks_math_2004_y*_g* _I* _g* enroll* if regular_hs == 1 & course_type == "math" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students students   using teachers_share_pooled, excel dec(3) nocons ctitle("Math, School FE, Control for Total Students")

	***ENGLISH --> STANFORD LANGUAGE***
	areg stanford_sd_lang_scale  post_share_students  share_students  students  post  stanf_lang_2004_y*_g* _I* _g* enroll* if regular_hs == 1 & course_type == "eng" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students students  using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, School FE, Control for Total Students")

	***SCIENCE  - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	areg  stanf_taks_sci  post_share_students  share_students  students  post stanf_science_2004_y*_g* _I* _g* enroll* if  regular_hs == 1  & course_type == "sci" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students students  using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, School FE, Control for Total Students")

	***SOC
	areg  stanf_taks_soc post_share_students  share_students  students post stanf_socialstu_2004_y*_g* _I* _g* enroll* if  regular_hs == 1  & course_type == "soc" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students  students using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, School FE, Control for Total Students")
	
	***MATH - STANF
	areg stanford_sd_math_scale post_share_students  share_students  students _I* _g* enroll* stanf_math_2004_y*_g*  if regular_hs == 1 & course_type == "math" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students  students using teachers_share_pooled, excel dec(3) nocons ctitle("Math - Stanf, School FE, , Control for Total Students")

*NO REWEIGHTING FOR SPLITTING STUDENTS ACROSS TEACHERS 
	use temp, clear
	xi i.grade*i.year, prefix(_g)
	xi i.female i.ethnicity i.econdis i.atrisk i.speced i.lep i.gifted 

	***MATH --> TAKS MATH
	areg taks_sd_scale_min_math post_share_students  share_students  post taks_math_2004_y*_g* _I* _g* enroll* if regular_hs == 1 & course_type == "math"  , cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students  using teachers_share_pooled, excel dec(3) nocons ctitle("Math, School FE, No Weight")

	***ENGLISH --> STANFORD LANGUAGE***
	areg stanford_sd_lang_scale  post_share_students  share_students   post  stanf_lang_2004_y*_g* _I* _g* enroll* if regular_hs == 1 & course_type == "eng"  , cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students  using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, School FE, No Weight")

	***SCIENCE  - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	areg  stanf_taks_sci  post_share_students  share_students    post stanf_science_2004_y*_g* _I* _g* enroll* if  regular_hs == 1  & course_type == "sci", cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, School FE, No Weight")

	***SOC
	areg  stanf_taks_soc post_share_students  share_students   post stanf_socialstu_2004_y*_g* _I* _g* enroll* if  regular_hs == 1  & course_type == "soc", cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, School FE, No Weight")
	
	***MATH - STANF
	areg stanford_sd_math_scale post_share_students  share_students  stanf_math_2004_y*_g*  _I* _g* enroll* if regular_hs == 1 & course_type == "math"  , cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students  using teachers_share_pooled, excel dec(3) nocons ctitle("Math - Stanf, School FE, , No Weight")
    
*USE INDIVIDUAL FE INSTEAD OF LAGGED SCORE
	use temp, clear
	xi i.grade*i.year, prefix(_g)
	xi i.female i.campus i.ethnicity i.econdis i.atrisk i.speced i.lep i.gifted 
	
	***MATH --> TAKS MATH
	areg taks_sd_scale_min_math post_share_students  share_students  post  _I* _g* enroll* if taks_math_2004 != . & regular_hs == 1 & course_type == "math" [pw = weight], cluster(campus) absorb(id)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Math, School FE, Student FE")

	***ENGLISH --> STANFORD LANGUAGE***
	areg stanford_sd_lang_scale  post_share_students  share_students   post   _I* _g* enroll* if stanf_lang_2004 != . & regular_hs == 1 & course_type == "eng" [pw = weight], cluster(campus) absorb(id)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, School FE, Student FE")

	***SCIENCE  - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	areg  stanf_taks_sci  post_share_students  share_students    post  _I* _g* enroll* if  stanf_science_2004 != .  & regular_hs == 1  & course_type == "sci"  [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, School FE, Student FE")

	***SOC
	areg  stanf_taks_soc post_share_students  share_students   post  _I* _g* enroll* if stanf_socialstu_2004 != . &  regular_hs == 1  & course_type == "soc"  [pw = weight], cluster(campus) absorb(school_year)	
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, School FE, Student FE")
	
	***MATH - STANF
	areg stanford_sd_math_scale post_share_students  share_students   _I* _g* enroll* if stanf_math_2004  != . & regular_hs == 1 & course_type == "math" [pw = weight], cluster(campus) absorb(id)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Math - Stanf, School FE, , Student FE")

*USE ALL SCHOOLS (INCL CHARTERS AND ALT)
	use temp, clear
	xi i.grade*i.year, prefix(_g)
	xi i.female i.ethnicity i.econdis i.atrisk i.speced i.lep i.gifted 

	***MATH --> TAKS MATH
	areg taks_sd_scale_min_math post_share_students  share_students  post taks_math_2004_y*_g* _I* _g* enroll* if course_type == "math" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Math, School FE, All Schools")

	***ENGLISH --> STANFORD LANGUAGE***
	areg stanford_sd_lang_scale  post_share_students  share_students   post  stanf_lang_2004_y*_g* _I* _g* enroll* if course_type == "eng" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, School FE, All Schools")

	***SCIENCE  - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	areg  stanf_taks_sci  post_share_students  share_students    post stanf_science_2004_y*_g* _I* _g* enroll* if  course_type == "sci" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, School FE, All Schools")

	***SOC
	areg  stanf_taks_soc post_share_students  share_students   post stanf_socialstu_2004_y*_g* _I* _g* enroll* if  course_type == "soc" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, School FE, All Schools")
	
	***MATH - STANF
	areg stanford_sd_math_scale post_share_students  share_students  _I* _g* enroll* stanf_math_2004_y*_g*  if course_type == "math" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Math - Stanf, School FE, , All Schools")

*DROP SPECIAL EDUCATION
	use temp, clear
	xi i.grade*i.year, prefix(_g)
	xi i.female i.ethnicity i.econdis i.atrisk i.speced i.lep i.gifted 

	***MATH --> TAKS MATH
	areg taks_sd_scale_min_math post_share_students  share_students  post taks_math_2004_y*_g* _I* _g* enroll* if regular_hs == 1 & speced != 1 & course_type == "math" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Math, School FE, No Spec")

	***ENGLISH --> STANFORD LANGUAGE***
	areg stanford_sd_lang_scale  post_share_students  share_students   post  stanf_lang_2004_y*_g* _I* _g* enroll* if regular_hs == 1 & speced != 1 & course_type == "eng" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, School FE, No Spec")

	***SCIENCE  - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	areg  stanf_taks_sci  post_share_students  share_students    post stanf_science_2004_y*_g* _I* _g* enroll* if regular_hs == 1 & speced != 1 &  course_type == "sci" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, School FE, No Spec")

	***SOC
	areg  stanf_taks_soc post_share_students  share_students   post stanf_socialstu_2004_y*_g* _I* _g* enroll* if regular_hs == 1 & speced != 1 & course_type == "soc" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, School FE, No Spec")
	
	***MATH - STANF
	areg stanford_sd_math_scale post_share_students  share_students  _I* _g* enroll* stanf_math_2004_y*_g*  if regular_hs == 1 & speced != 1 &  course_type == "math" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Math - Stanf, School FE, , No Spec")

*USE LOG(PERCENT)
	use temp, clear
	gen percent_students = share_students*100
	drop if percent_students < 1
	gen log_students = log(percent_students)
	gen post_log_students = post*log_students
	xi i.grade*i.year, prefix(_g)
	xi i.female i.ethnicity i.econdis i.atrisk i.speced i.lep i.gifted 

	***MATH --> TAKS MATH
	areg taks_sd_scale_min_math post_log_students  log_students  post taks_math_2004_y*_g* _I* _g* enroll* if regular_hs == 1 & course_type == "math" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_log_students  log_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Math, School FE, Logs")

	***ENGLISH --> STANFORD LANGUAGE***
	areg stanford_sd_lang_scale  post_log_students  log_students   post  stanf_lang_2004_y*_g* _I* _g* enroll* if regular_hs == 1 & course_type == "eng" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_log_students  log_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, School FE,  Logs")

	***SCIENCE  - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	areg  stanf_taks_sci  post_log_students  log_students    post stanf_science_2004_y*_g* _I* _g* enroll* if regular_hs == 1  &  course_type == "sci" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_log_students  log_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, School FE,  Logs")

	***SOC
	areg  stanf_taks_soc post_log_students  log_students   post stanf_socialstu_2004_y*_g* _I* _g* enroll* if regular_hs == 1 & course_type == "soc" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_log_students  log_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, School FE,  Logs")
	
	***MATH - STANF
	areg stanford_sd_math_scale post_log_students  log_students  _I* _g* enroll* stanf_math_2004_y*_g*  if regular_hs == 1  &  course_type == "math" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_log_students  log_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Math - Stanf, School FE, Logs")

*USE DEPARTMENT SIZE ONLY (no school-year FE)
	use temp, clear
	xi i.grade*i.year, prefix(_g)
	xi i.female i.ethnicity i.econdis i.atrisk i.speced i.lep i.gifted 


	***MATH --> TAKS MATH
	areg taks_sd_scale_min_math post_teachers_grade teachers_grade  post taks_math_2004_y*_g* _I* _g* enroll* if regular_hs == 1 & course_type == "math" [pw = weight], cluster(campus) absorb(campus)
	outreg2 post_teachers_grade teachers_grade   using teachers_share_pooled, excel dec(3) nocons ctitle("Math, School FE, Dept Size Only")

	***ENGLISH --> STANFORD LANGUAGE***
	areg stanford_sd_lang_scale  post_teachers_grade teachers_grade   post  stanf_lang_2004_y*_g* _I* _g* enroll* if regular_hs == 1 & course_type == "eng" [pw = weight], cluster(campus) absorb(campus)
	outreg2 post_teachers_grade teachers_grade   using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, School FE, Dept Size Only")

	***SCIENCE  - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	areg  stanf_taks_sci  post_teachers_grade teachers_grade    post stanf_science_2004_y*_g* _I* _g* enroll* if regular_hs == 1  &  course_type == "sci" [pw = weight], cluster(campus) absorb(campus)
	outreg2 post_teachers_grade teachers_grade   using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, School FE, Dept Size Only")

	***SOC
	areg  stanf_taks_soc post_teachers_grade teachers_grade   post stanf_socialstu_2004_y*_g* _I* _g* enroll* if regular_hs == 1 & course_type == "soc" [pw = weight], cluster(campus) absorb(campus)
	outreg2 post_teachers_grade teachers_grade   using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, School FE, Dept Size Only")
	
	***MATH - STANF
	areg stanford_sd_math_scale post_teachers_grade teachers_grade  _I* _g* enroll* stanf_math_2004_y*_g*  if regular_hs == 1  &  course_type == "math" [pw = weight], cluster(campus) absorb(campus)
	outreg2 post_teachers_grade teachers_grade  using teachers_share_pooled, excel dec(3) nocons ctitle("Math - Stanf, School FE, Dept Size Only")


	
*INCLUDE ALL LEP & SPECED CLASSES
	use temp_b, clear
	xi i.grade*i.year, prefix(_g)
	xi i.female i.ethnicity i.econdis i.atrisk i.speced i.lep i.gifted 

	***MATH --> TAKS MATH
	areg taks_sd_scale_min_math post_share_students  share_students  post taks_math_2004_y*_g* _I* _g* enroll* if regular_hs == 1 & course_type == "math" [pw = weight], cluster(campus) absorb(campus)
	outreg2 post_share_students  share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Math, School FE, All Classes")

	***ENGLISH --> STANFORD LANGUAGE***
	areg stanford_sd_lang_scale  post_share_students  share_students   post  stanf_lang_2004_y*_g* _I* _g* enroll* if regular_hs == 1 & course_type == "eng" [pw = weight], cluster(campus) absorb(campus)
	outreg2 post_share_students  share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, School FE, All Classes")

	***SCIENCE  - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	areg  stanf_taks_sci  post_share_students  share_students     post stanf_science_2004_y*_g* _I* _g* enroll* if regular_hs == 1  &  course_type == "sci" [pw = weight], cluster(campus) absorb(campus)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, School FE, All Classes")

	***SOC
	areg  stanf_taks_soc post_share_students  share_students    post stanf_socialstu_2004_y*_g* _I* _g* enroll* if regular_hs == 1 & course_type == "soc" [pw = weight], cluster(campus) absorb(campus)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, School FE, All Classes")
	
	***MATH - STANF
	areg stanford_sd_math_scale post_share_students  share_students   _I* _g* enroll* stanf_math_2004_y*_g*  if regular_hs == 1  &  course_type == "math" [pw = weight], cluster(campus) absorb(campus)
	outreg2 post_share_students  share_students  students using teachers_share_pooled, excel dec(3) nocons ctitle("Math - Stanf, School FE, All Classes")

	
	
*DROP LEP
	use temp, clear
	xi i.grade*i.year, prefix(_g)
	xi i.female i.ethnicity i.econdis i.atrisk i.speced i.lep i.gifted 
	keep if lep == 0
	
	***MATH --> TAKS MATH
	areg taks_sd_scale_min_math post_share_students  share_students  post taks_math_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "math" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Math, School FE, No LEP")

	***ENGLISH --> STANFORD LANGUAGE***
	areg stanford_sd_lang_scale  post_share_students  share_students   post  stanf_lang_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "eng" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, School FE, No LEP")

	***SCIENCE  - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	areg  stanf_taks_sci  post_share_students  share_students    post stanf_science_2004_y*_g* _I* _g* enroll* if regular_hs == 1 &  course_type == "sci" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, School FE, No LEP")

	***SOC
	areg  stanf_taks_soc post_share_students  share_students   post stanf_socialstu_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "soc" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, School FE, No LEP")
	
	***MATH - STANF
	areg stanford_sd_math_scale post_share_students  share_students  _I* _g* enroll* stanf_math_2004_y*_g*  if regular_hs == 1 &  course_type == "math" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Math - Stanf, School FE, , No ")


*DROP SWITCHERS
	use temp, clear
	xi i.grade*i.year, prefix(_g)
	xi i.female i.ethnicity i.econdis i.atrisk i.speced i.lep i.gifted 
	keep if changeschools == 0
	
	***MATH --> TAKS MATH
	areg taks_sd_scale_min_math post_share_students  share_students  post taks_math_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "math" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Math, School FE, No switch")

	***ENGLISH --> STANFORD LANGUAGE***
	areg stanford_sd_lang_scale  post_share_students  share_students   post  stanf_lang_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "eng" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, School FE, No switch")

	***SCIENCE  - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	areg  stanf_taks_sci  post_share_students  share_students    post stanf_science_2004_y*_g* _I* _g* enroll* if regular_hs == 1 &  course_type == "sci" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, School FE, No switch")

	***SOC
	areg  stanf_taks_soc post_share_students  share_students   post stanf_socialstu_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "soc" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, School FE, No switch")
	
	***MATH - STANF
	areg stanford_sd_math_scale post_share_students  share_students  _I* _g* enroll* stanf_math_2004_y*_g*  if regular_hs == 1 &  course_type == "math" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Math - Stanf, School FE, , No switch ")

*DROP ENTERERS
	use temp, clear
	xi i.grade*i.year, prefix(_g)
	xi i.female i.ethnicity i.econdis i.atrisk i.speced i.lep i.gifted 
	keep if enterdistrict == 0
	
	***MATH --> TAKS MATH
	areg taks_sd_scale_min_math post_share_students  share_students  post taks_math_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "math" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Math, School FE, No enter")

	***ENGLISH --> STANFORD LANGUAGE***
	areg stanford_sd_lang_scale  post_share_students  share_students   post  stanf_lang_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "eng" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, School FE, No enter")

	***SCIENCE  - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	areg  stanf_taks_sci  post_share_students  share_students    post stanf_science_2004_y*_g* _I* _g* enroll* if regular_hs == 1 &  course_type == "sci" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, School FE, No enter")

	***SOC
	areg  stanf_taks_soc post_share_students  share_students   post stanf_socialstu_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "soc" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, School FE, No enter")
	
	***MATH - STANF
	areg stanford_sd_math_scale post_share_students  share_students  _I* _g* enroll* stanf_math_2004_y*_g*  if regular_hs == 1 &  course_type == "math" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Math - Stanf, School FE, , No enter ")


*DROP APOLLO SCHOOLS (APOLLO PROGRAM STARTS IN 2010-11 BUT THIS TEST IS IN CASE OF ANTICIPATION EFFECTS)
	use temp, clear
	xi i.grade*i.year, prefix(_g)
	xi i.female i.ethnicity i.econdis i.atrisk i.speced i.lep i.gifted 
	drop if campus == 6 | campus == 7 | campus == 9 | campus == 23
	
	***MATH --> TAKS MATH
	areg taks_sd_scale_min_math post_share_students  share_students  post taks_math_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "math" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Math, School FE, No Apollo")

	***ENGLISH --> STANFORD LANGUAGE***
	areg stanford_sd_lang_scale  post_share_students  share_students   post  stanf_lang_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "eng" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, School FE, No Apollo")

	***SCIENCE  - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	areg  stanf_taks_sci  post_share_students  share_students    post stanf_science_2004_y*_g* _I* _g* enroll* if regular_hs == 1 &  course_type == "sci" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, School FE, No Apollo")

	***SOC
	areg  stanf_taks_soc post_share_students  share_students   post stanf_socialstu_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "soc" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, School FE, No Apollo")
	
	***MATH - STANF
	areg stanford_sd_math_scale post_share_students  share_students post _I* _g* enroll* stanf_math_2004_y*_g*  if regular_hs == 1 &  course_type == "math" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Math - Stanf, School FE, , No Apollo ")



**ESTIMATE SEPARATELY BY GRADE***

	use temp, clear
	xi i.grade*i.year, prefix(_g)
	xi i.female i.ethnicity i.econdis i.atrisk i.speced i.lep i.gifted 


	*9TH GRADE 
	
	***MATH --> TAKS MATH
	areg taks_sd_scale_min_math post_share_students share_students   post taks_math_2004_y*_g* _I* _g* enroll* if grade == 9 &  regular_hs == 1  & course_type == "math" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Math, School FE, 9TH GRADE")

	***ENGLISH --> STANFORD LANGUAGE***
	areg stanford_sd_lang_scale post_share_students   share_students     post  stanf_lang_2004_y*_g* _I* _g* enroll* if grade == 9 &  regular_hs == 1  & course_type == "eng" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, School FE, 9TH GRADE")

	***SCIENCE  - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	areg  stanf_taks_sci  post_share_students   share_students  post stanf_science_2004_y*_g* _I* _g* enroll* if grade == 9 &  regular_hs == 1 &  course_type == "sci" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, School FE, 9TH GRADE")

	***SOC
	areg  stanf_taks_soc post_share_students share_students  post stanf_socialstu_2004_y*_g* _I* _g* enroll* if grade == 9 & regular_hs == 1  & course_type == "soc" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students  using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, School FE, 9TH GRADE")
	
	*10TH GRADE 
	
	***MATH --> TAKS MATH
	areg taks_sd_scale_min_math post_share_students share_students   post taks_math_2004_y*_g* _I* _g* enroll* if grade == 10 &  regular_hs == 1  & course_type == "math" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Math, School FE, 10th GRADE")

	***ENGLISH --> STANFORD LANGUAGE***
	areg stanford_sd_lang_scale post_share_students   share_students     post  stanf_lang_2004_y*_g* _I* _g* enroll* if grade == 10 &  regular_hs == 1  & course_type == "eng" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, School FE, 10th GRADE")

	***SCIENCE  - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	areg  stanf_taks_sci  post_share_students   share_students  post stanf_science_2004_y*_g* _I* _g* enroll* if grade == 10 &  regular_hs == 1 &  course_type == "sci" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, School FE, 10th GRADE")

	***SOC
	areg  stanf_taks_soc post_share_students share_students  post stanf_socialstu_2004_y*_g* _I* _g* enroll* if grade == 10 & regular_hs == 1  & course_type == "soc" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students  using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, School FE, 10th GRADE")
	
	
	*11TH GRADE 
	
	***MATH --> TAKS MATH
	areg taks_sd_scale_min_math post_share_students share_students   post taks_math_2004_y*_g* _I* _g* enroll* if grade == 11 &  regular_hs == 1  & course_type == "math" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Math, School FE, 11TH GRADE")

	***ENGLISH --> STANFORD LANGUAGE***
	areg stanford_sd_lang_scale post_share_students   share_students     post  stanf_lang_2004_y*_g* _I* _g* enroll* if grade == 11 &  regular_hs == 1  & course_type == "eng" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, School FE, 11TH GRADE")

	***SCIENCE  - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	areg  stanf_taks_sci  post_share_students   share_students  post stanf_science_2004_y*_g* _I* _g* enroll* if grade == 11 &  regular_hs == 1 &  course_type == "sci" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, School FE, 11TH GRADE")

	***SOC
	areg  stanf_taks_soc post_share_students share_students  post stanf_socialstu_2004_y*_g* _I* _g* enroll* if grade == 11 & regular_hs == 1  & course_type == "soc" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students  using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, School FE, 11TH GRADE")
	
	


*DEPARTMENT-GRADE FE'S
	use temp, clear
	gen double school_grade= campus*10000000000 + grade
	xi i.grade*i.year , prefix(_g)
	xi i.female i.ethnicity i.econdis i.atrisk i.speced i.lep i.gifted 
	
	***MATH --> TAKS MATH
	areg taks_sd_scale_min_math post_share_students  share_students  post taks_math_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "math" [pw = weight], cluster(campus) absorb(school_grade)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Math, Dept-Grade FE")

	***ENGLISH --> STANFORD LANGUAGE***
	areg stanford_sd_lang_scale  post_share_students  share_students   post  stanf_lang_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "eng" [pw = weight], cluster(campus) absorb(school_grade)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, Dept-Grade FE")

	***SCIENCE  - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	areg  stanf_taks_sci  post_share_students  share_students    post stanf_science_2004_y*_g* _I* _g* enroll* if regular_hs == 1 &  course_type == "sci" [pw = weight], cluster(campus) absorb(school_grade)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, Dept-Grade FE")

	***SOC
	areg  stanf_taks_soc post_share_students  share_students   post stanf_socialstu_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "soc" [pw = weight], cluster(campus) absorb(school_grade)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, Dept-Grade FE")
	
	***MATH - STANF
	areg stanford_sd_math_scale post_share_students  share_students post _I* _g* enroll* stanf_math_2004_y*_g*  if regular_hs == 1 &  course_type == "math" [pw = weight], cluster(campus) absorb(school_grade)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Math - Stanf, Dept-Grade FE ")
	
	
	
*DEPARTMENT-GRADE-YEAR FE'S
	use temp, clear
	gen double school_grade_year = campus*10000000000 + year*100 + grade
	xi i.grade*i.year , prefix(_g)
	xi i.female i.ethnicity i.econdis i.atrisk i.speced i.lep i.gifted 
	
	***MATH --> TAKS MATH
	areg taks_sd_scale_min_math post_share_students  share_students  post taks_math_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "math" [pw = weight], cluster(campus) absorb(school_grade_year)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Math, Dept-Grade-Year FE")

	***ENGLISH --> STANFORD LANGUAGE***
	areg stanford_sd_lang_scale  post_share_students  share_students   post  stanf_lang_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "eng" [pw = weight], cluster(campus) absorb(school_grade_year)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, Dept-Grade-Year FE")

	***SCIENCE  - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	areg  stanf_taks_sci  post_share_students  share_students    post stanf_science_2004_y*_g* _I* _g* enroll* if regular_hs == 1 &  course_type == "sci" [pw = weight], cluster(campus) absorb(school_grade_year)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, Dept-Grade-Year FE")

	***SOC
	areg  stanf_taks_soc post_share_students  share_students   post stanf_socialstu_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "soc" [pw = weight], cluster(campus) absorb(school_grade_year)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, Dept-Grade-Year FE")
	
	***MATH - STANF
	areg stanford_sd_math_scale post_share_students  share_students post _I* _g* enroll* stanf_math_2004_y*_g*  if regular_hs == 1 &  course_type == "math" [pw = weight], cluster(campus) absorb(school_grade_year)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Math - Stanf, Dept-Grade-Year FE ")



	
*Instrument for Share using Current Dept. Size
	use temp, clear
	
	gen inv_dept_math = 1/teachers_grade_math
	gen post_inv_dept_math = post*inv_dept_math
	
	gen inv_dept_eng  = 1/teachers_grade_eng 
	gen post_inv_dept_eng  = post*inv_dept_eng 
		
	gen inv_dept_sci  = 1/teachers_grade_sci 
	gen post_inv_dept_sci = post*inv_dept_sci 
	
	gen inv_dept_soc  = 1/teachers_grade_soc 
	gen post_inv_dept_soc  = post*inv_dept_soc
	
	
	xi i.grade*i.year , prefix(_g)
	xi i.female i.ethnicity i.econdis i.atrisk i.speced i.lep i.gifted i.campus
	
	***MATH --> TAKS MATH
	reg post_share_students post_inv_dept_math inv_dept_math  post taks_math_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "math" [pw = weight], cluster(campus) 
	outreg2 post_inv_dept_math  inv_dept_math  using teachers_share_pooled, excel dec(3) nocons ctitle("Math, dept size instr, fs-post")
	reg  share_students post_inv_dept_math inv_dept_math  post taks_math_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "math" [pw = weight], cluster(campus) 
	outreg2 post_inv_dept_math  inv_dept_math  using teachers_share_pooled, excel dec(3) nocons ctitle("Math, dept size instr, fs-share")
		
	ivreg taks_sd_scale_min_math (post_share_students share_students = post_inv_dept_math inv_dept_math )  post taks_math_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "math" [pw = weight], cluster(campus) 
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Math, dept size instr, ss")

	***ENGLISH --> STANFORD LANGUAGE***
	reg post_share_students post_inv_dept_eng inv_dept_eng post stanf_lang_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "eng" [pw = weight], cluster(campus) 
	outreg2 post_inv_dept_eng  inv_dept_eng using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, dept size instr, fs-post")
	reg share_students post_inv_dept_eng inv_dept_eng post stanf_lang_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "eng" [pw = weight], cluster(campus) 
	outreg2 post_inv_dept_eng  inv_dept_eng   using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, dept size instr, fs-share")
	
	ivreg stanford_sd_lang_scale  (post_share_students share_students = post_inv_dept_eng inv_dept_eng)    post  stanf_lang_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "eng" [pw = weight], cluster(campus) 
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, dept size instr, ss")

	***SCIENCE  - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	reg post_share_students post_inv_dept_sci  inv_dept_sci post  stanf_science_2004_y*_g*  _I* _g* enroll* if regular_hs == 1  & course_type == "sci" [pw = weight], cluster(campus) 
	outreg2 post_inv_dept_sci   inv_dept_sci  using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, dept size instr, fs-post")
	reg share_students post_inv_dept_sci   inv_dept_sci post  stanf_science_2004_y*_g*  _I* _g* enroll* if regular_hs == 1  & course_type == "sci" [pw = weight], cluster(campus) 
	outreg2 post_inv_dept_sci   inv_dept_sci  using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, dept size instr, fs-share")
		
	
	ivreg  stanf_taks_sci  (post_share_students share_students =post_inv_dept_sci inv_dept_sci)     post stanf_science_2004_y*_g* _I* _g* enroll* if regular_hs == 1 &  course_type == "sci" [pw = weight], cluster(campus) 
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Sci,dept size instr, ss")

	***SOC
	reg post_share_students post_inv_dept_soc   inv_dept_soc post stanf_socialstu_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "soc" [pw = weight], cluster(campus) 
	outreg2 post_inv_dept_soc  inv_dept_soc  using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, dept size instr, fs-post")
	reg share_students post_inv_dept_soc   inv_dept_soc post stanf_socialstu_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "soc" [pw = weight], cluster(campus) 
	outreg2 post_inv_dept_soc  inv_dept_soc  using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, dept size instr, fs-share")
	
	ivreg  stanf_taks_soc (post_share_students share_students = post_inv_dept_soc inv_dept_soc)    post stanf_socialstu_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "soc" [pw = weight], cluster(campus) 
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, dept size instr, ss")
	
	***MATH - STANF
	reg post_share_students post_inv_dept_math  inv_dept_math post stanf_math_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "math" [pw = weight], cluster(campus) 
	outreg2 post_inv_dept_math inv_dept_math   using teachers_share_pooled, excel dec(3) nocons ctitle("Math - Stanf, dept size instr, fs-post")
	reg share_students post_inv_dept_math  inv_dept_math post stanf_math_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "math" [pw = weight], cluster(campus) 
	outreg2 post_inv_dept_math  inv_dept_math   using teachers_share_pooled, excel dec(3) nocons ctitle("Math - Stanf, dept size instr, fs-share")
		
	
	ivreg stanford_sd_math_scale (post_share_students share_students = post_inv_dept_math inv_dept_math)  post _I* _g* enroll* stanf_math_2004_y*_g*  if regular_hs == 1 &  course_type == "math" [pw = weight], cluster(campus) 
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Math - Stanf, dept size instr, ss ")



**ESTIMATE IMPACTS THAT VARY BY CHARACTERISTICS OF STUDENT-YEAR/TEACHER-YEAR/SCHOOL-YEAR

  **CALCULATE MEDIANS - STUDENT LEVEL***
  use temp, clear
  drop if econdis == .
  keep id year tch_number campus lstanford_sd_*_scale econdis
  gen frp_s = econdis == 1 | econdis == 2 if econdis != .
  
  egen math_smed = median(lstanford_sd_math_scale), by(year)
  egen lang_smed = median(lstanford_sd_lang_scale), by(year)
  egen soc_smed = median(lstanford_sd_socialstu_scale), by(year)
  egen sci_smed = median(lstanford_sd_science_scale), by(year)
  
  sort id year
  save student_medians.dta, replace
  
  *CALCULATE MEDIANS - TEACHER LEVEL
  collapse (mean) frp lstanford_sd_*_scale, by(tch_num year)
  
  egen math_tmed = median(lstanford_sd_math_scale), by(year)
  egen lang_tmed = median(lstanford_sd_lang_scale), by(year)
  egen soc_tmed = median(lstanford_sd_socialstu_scale), by(year)
  egen sci_tmed = median(lstanford_sd_science_scale), by(year)
  egen frp_tmed = median(frp), by(year)
  
  rename lstanford_sd_math_scale math_tmean
  rename lstanford_sd_lang_scale lang_tmean
  rename lstanford_sd_socialstu_scale soc_tmean
  rename lstanford_sd_science_scale sci_tmean
  rename frp_s frp_tmean

  
 
  sort tch_num year
  save teacher_medians.dta, replace
  
  
  *CALCULATE MEDIANS - SCHOOL LEVEL
  use student_medians.dta, clear
  collapse (mean) frp lstanford_sd_*_scale, by(campus year)
  
  egen math_cmed = median(lstanford_sd_math_scale), by(year)
  egen lang_cmed = median(lstanford_sd_lang_scale), by(year)
  egen soc_cmed = median(lstanford_sd_socialstu_scale), by(year)
  egen sci_cmed = median(lstanford_sd_science_scale), by(year)
  egen frp_cmed = median(frp), by(year)
 
  rename lstanford_sd_math_scale math_cmean
  rename lstanford_sd_lang_scale lang_cmean
  rename lstanford_sd_socialstu_scale soc_cmean
  rename lstanford_sd_science_scale sci_cmean
  rename frp_s frp_cmean

 
  sort campus year
  save campus_medians.dta, replace  
 
  *MERGE INTO ANALYSIS FILE
  use temp, clear
  sort id year
  merge id year using student_medians.dta, _merge(_mergestudent) nokeep
  
  sort tch_num year
  merge tch_num year using teacher_medians.dta, _merge(_mergeteacher) nokeep
  
  sort campus year
  merge campus year using campus_medians.dta, _merge(_mergecampus) nokeep
  
  save temp2, replace
  
  
  *REGRESSIONS
 
	xi i.grade*i.year, prefix(_g)
	xi i.female i.ethnicity i.econdis i.atrisk i.speced i.lep i.gifted
	xi i.campus*i.year, prefix(_c)
	

	***STUDENT LEVEL - ACHIEVEMENT***
	local level = "s"
	
	
	*BELOW MEDIAN
	
	***MATH --> TAKS MATH
	areg taks_sd_scale_min_math post_share_students share_students post taks_math_2004_y*_g* _I* _g*  enroll* if lstanford_sd_math_scale < math_`level'med & regular_hs == 1 & course_type == "math" [pw= weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Math, level `level', below med achieve")
    
	***ENGLISH --> STANFORD LANGUAGE***
	areg stanford_sd_lang_scale  post_share_students share_students post  stanf_lang_2004_y*_g* _I* _g*  enroll* if  lstanford_sd_lang_scale < lang_`level'med &  regular_hs == 1 & course_type == "eng" [pw = weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students  share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, level `level', below med achieve")

	***SCIENCE - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	areg  stanf_taks_sci  post_share_students post share_students stanf_science_2004_y*_g*  _I* _g*  enroll* if lstanford_sd_science_scale < sci_`level'med & regular_hs == 1  & course_type == "sci" [pw = weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, level `level', below med achieve")
	
	*SOC
	areg  stanf_taks_soc post_share_students  share_students post stanf_socialstu_2004_y*_g*  _I* _g*  enroll* if  lstanford_sd_socialstu_scale < soc_`level'med &  regular_hs == 1  & course_type == "soc" [pw  = weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, level `level', below med achieve")
 	

    *ABOVE MEDIAN
	local level = "s"

	***MATH --> TAKS MATH
	areg taks_sd_scale_min_math post_share_students  share_students post taks_math_2004_y*_g* _I* _g*  enroll* if lstanford_sd_math_scale >= math_`level'med & regular_hs == 1 & course_type == "math" [pw= weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Math, level `level', above med achieve")
    
	***ENGLISH --> STANFORD LANGUAGE***
	areg stanford_sd_lang_scale  post_share_students  share_students post  stanf_lang_2004_y*_g* _I* _g*  enroll* if  lstanford_sd_lang_scale >= lang_`level'med &  regular_hs == 1 & course_type == "eng" [pw = weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, level `level', above med achieve")

	***SCIENCE - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	areg  stanf_taks_sci  post_share_students share_students post stanf_science_2004_y*_g*  _I* _g*  enroll* if lstanford_sd_science_scale >= sci_`level'med & regular_hs == 1  & course_type == "sci" [pw = weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, level `level', above med achieve")
	
	*SOC
	areg  stanf_taks_soc post_share_students share_students post stanf_socialstu_2004_y*_g*  _I* _g*  enroll* if  lstanford_sd_socialstu_scale >= soc_`level'med &  regular_hs == 1  & course_type == "soc" [pw  = weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, level `level', above med achieve")


 
	***TEACHER LEVEL - ACHIEVEMENT***
	local level = "t"
	
	
	*BELOW MEDIAN
	
	***MATH --> TAKS MATH
	areg taks_sd_scale_min_math post_share_students share_students post taks_math_2004_y*_g* _I* _g*  enroll* if math_`level'mean < math_`level'med & regular_hs == 1 & course_type == "math" [pw= weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Math, level `level', below med achieve")
    
	***ENGLISH --> STANFORD LANGUAGE***
	areg stanford_sd_lang_scale  post_share_students share_students post  stanf_lang_2004_y*_g* _I* _g*  enroll* if  lang_`level'mean < lang_`level'med &  regular_hs == 1 & course_type == "eng" [pw = weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, level `level', below med achieve")

	***SCIENCE - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	areg  stanf_taks_sci  post_share_students share_students  post stanf_science_2004_y*_g*  _I* _g*  enroll* if sci_`level'mean < sci_`level'med & regular_hs == 1  & course_type == "sci" [pw = weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, level `level', below med achieve")
	
	*SOC
	areg  stanf_taks_soc post_share_students share_students post stanf_socialstu_2004_y*_g*  _I* _g*  enroll* if  soc_`level'mean < soc_`level'med &  regular_hs == 1  & course_type == "soc" [pw  = weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, level `level', below med achieve")
 	
***STANFORD MATH
	areg stanford_sd_math_scale  post_share_students share_students  post  stanf_math_2004_y*_g* _I* _g* enroll* if math_`level'mean < math_`level'med & regular_hs == 1 & course_type == "math" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Math, Non-Inct Exams, Stanf Math, below med achieve")

	***READING FOR ENGLISH TEACHERS
	areg stanford_sd_read_scale  post_share_students share_students  post  stanf_lang_2004_y*_g* _I* _g* enroll* if lang_`level'mean < lang_`level'med & regular_hs == 1 & course_type == "eng" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, Non-Inct Exams, Stanf Reading, below med achieve")

  	***science 10th & 11th grade
	areg stanford_sd_science_scale  post_share_students share_students  post  stanf_science_2004_y*_g* _I* _g* enroll* if sci_`level'mean < sci_`level'med & regular_hs == 1 & course_type == "sci"  & (grade == 10 | grade == 11) [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("SCI, Non-Inct Exams, Stanf Sci 10th 11th, below med achieve")

  	***soc 10th & 11th grade
	areg stanford_sd_socialstu_scale  post_share_students share_students  post  stanf_socialstu_2004_y*_g* _I* _g* enroll* if soc_`level'mean < soc_`level'med &  regular_hs == 1 & course_type == "soc"  & (grade == 10 | grade == 11) [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("soc, Non-Inct Exams, Stanf soc 10th 11th, below med achieve")
  
	***compare to science 9th grade
	areg stanford_sd_science_scale  post_share_students share_students  post  stanf_science_2004_y*_g* _I* _g* enroll* if sci_`level'mean < sci_`level'med  & regular_hs == 1 & course_type == "sci"  & (grade == 9) [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("SCI, Inct Exams, Stanf Sci 9th, below med achieve")

	*** compare to soc 9th grade
	areg stanford_sd_socialstu_scale  post_share_students share_students  post  stanf_socialstu_2004_y*_g* _I* _g* enroll* if soc_`level'mean < soc_`level'med &  regular_hs == 1 & course_type == "soc"  & (grade == 9) [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("soc, Inct Exams, Stanf soc 9th, below med achieve")  
  
  
	

    *ABOVE MEDIAN
	
	***MATH --> TAKS MATH
	areg taks_sd_scale_min_math post_share_students share_students post taks_math_2004_y*_g* _I* _g*  enroll* if math_`level'mean >= math_`level'med & regular_hs == 1 & course_type == "math" [pw= weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Math, level `level', above med achieve")
    
	***ENGLISH --> STANFORD LANGUAGE***
	areg stanford_sd_lang_scale  post_share_students  share_students post  stanf_lang_2004_y*_g* _I* _g*  enroll* if  lang_`level'mean >= lang_`level'med &  regular_hs == 1 & course_type == "eng" [pw = weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, level `level', above med achieve")

	***SCIENCE - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	areg  stanf_taks_sci  post_share_students share_students post stanf_science_2004_y*_g*  _I* _g*  enroll* if sci_`level'mean  >= sci_`level'med & regular_hs == 1  & course_type == "sci" [pw = weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, level `level', above med achieve")
	
	*SOC
	areg  stanf_taks_soc post_share_students share_students post stanf_socialstu_2004_y*_g*  _I* _g*  enroll* if  soc_`level'mean >= soc_`level'med &  regular_hs == 1  & course_type == "soc" [pw  = weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, level `level', above med achieve")
 	
	***STANFORD MATH
	areg stanford_sd_math_scale  post_share_students share_students  post  stanf_math_2004_y*_g* _I* _g* enroll* if  math_`level'mean >= math_`level'med &  regular_hs == 1 & course_type == "math" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Math, Non-Inct Exams, Stanf Math, above med achieve")

	***READING FOR ENGLISH TEACHERS
	areg stanford_sd_read_scale  post_share_students share_students  post  stanf_lang_2004_y*_g* _I* _g* enroll* if lang_`level'mean >= lang_`level'med &  regular_hs == 1 & course_type == "eng" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, Non-Inct Exams, Stanf Reading, above med achieve")

  	***science 10th & 11th grade
	areg stanford_sd_science_scale  post_share_students share_students  post  stanf_science_2004_y*_g* _I* _g* enroll* if sci_`level'mean  >= sci_`level'med & regular_hs == 1 & course_type == "sci"  & (grade == 10 | grade == 11) [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("SCI, Non-Inct Exams, Stanf Sci 10th 11th, above med achieve")

  	***soc 10th & 11th grade
	areg stanford_sd_socialstu_scale  post_share_students share_students  post  stanf_socialstu_2004_y*_g* _I* _g* enroll* if soc_`level'mean >= soc_`level'med &   regular_hs == 1 & course_type == "soc"  & (grade == 10 | grade == 11) [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("soc, Non-Inct Exams, Stanf soc 10th 11th, above med achieve")
  
	***compare to science 9th grade
	areg stanford_sd_science_scale  post_share_students share_students  post  stanf_science_2004_y*_g* _I* _g* enroll* if sci_`level'mean  >= sci_`level'med & regular_hs == 1 & course_type == "sci"  & (grade == 9) [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("SCI, Inct Exams, Stanf Sci 9th, above med achieve")

	*** compare to soc 9th grade
	areg stanford_sd_socialstu_scale  post_share_students share_students  post  stanf_socialstu_2004_y*_g* _I* _g* enroll* if soc_`level'mean >= soc_`level'med &   regular_hs == 1 & course_type == "soc"  & (grade == 9) [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("soc, Inct Exams, Stanf soc 9th, above med achieve")  
  
  
   
   
	***CAMPUS LEVEL - ACHIEVEMENT***
	local level = "c"
	
	
	*BELOW MEDIAN
	
	***MATH --> TAKS MATH
	areg taks_sd_scale_min_math post_share_students share_students post taks_math_2004_y*_g* _I* _g*  enroll* if  math_`level'mean < math_`level'med & regular_hs == 1 & course_type == "math" [pw= weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Math, level `level', below med achieve")
    
	***ENGLISH --> STANFORD LANGUAGE***
	areg stanford_sd_lang_scale  post_share_students share_students post  stanf_lang_2004_y*_g* _I* _g*  enroll* if  lang_`level'mean < lang_`level'med &  regular_hs == 1 & course_type == "eng" [pw = weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, level `level', below med achieve")

	***SCIENCE - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	areg  stanf_taks_sci  post_share_students  share_students post stanf_science_2004_y*_g*  _I* _g*  enroll* if sci_`level'mean < sci_`level'med & regular_hs == 1  & course_type == "sci" [pw = weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, level `level', below med achieve")
	
	*SOC
	areg  stanf_taks_soc post_share_students share_students post stanf_socialstu_2004_y*_g*  _I* _g*  enroll* if  soc_`level'mean  < soc_`level'med &  regular_hs == 1  & course_type == "soc" [pw  = weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, level `level', below med achieve")
 	

    *ABOVE MEDIAN
	
	***MATH --> TAKS MATH
	areg taks_sd_scale_min_math post_share_students share_students post taks_math_2004_y*_g* _I* _g*  enroll* if math_`level'mean >= math_`level'med & regular_hs == 1 & course_type == "math" [pw= weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Math, level `level', above med achieve")
    
	***ENGLISH --> STANFORD LANGUAGE***
	areg stanford_sd_lang_scale  post_share_students  share_students post  stanf_lang_2004_y*_g* _I* _g*  enroll* if  lang_`level'mean >= lang_`level'med &  regular_hs == 1 & course_type == "eng" [pw = weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students  share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, level `level', above med achieve")

	***SCIENCE - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	areg  stanf_taks_sci  post_share_students share_students post stanf_science_2004_y*_g*  _I* _g*  enroll* if sci_`level'mean  >= sci_`level'med & regular_hs == 1  & course_type == "sci" [pw = weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, level `level', above med achieve")
	
	*SOC
	areg  stanf_taks_soc post_share_students share_students post stanf_socialstu_2004_y*_g*  _I* _g*  enroll* if  soc_`level'mean  >= soc_`level'med &  regular_hs == 1  & course_type == "soc" [pw  = weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, level `level', above med achieve")
 	

   
	***STUDENT LEVEL - FRP***
	local level = "s"
	
	
	*FRP
	
	***MATH --> TAKS MATH
	areg taks_sd_scale_min_math post_share_students share_students post taks_math_2004_y*_g* _I* _g*  enroll* if frp_s == 1 & regular_hs == 1 & course_type == "math" [pw= weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students share_students  using teachers_share_pooled, excel dec(3) nocons ctitle("Math, level `level', frp")
    
	***ENGLISH --> STANFORD LANGUAGE***
	areg stanford_sd_lang_scale  post_share_students share_students  post  stanf_lang_2004_y*_g* _I* _g*  enroll* if  frp_s == 1 &  regular_hs == 1 & course_type == "eng" [pw = weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students share_students  using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, level `level', frp")

	***SCIENCE - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	areg  stanf_taks_sci  post_share_students share_students post stanf_science_2004_y*_g*  _I* _g*  enroll* if frp_s == 1 & regular_hs == 1  & course_type == "sci" [pw = weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, level `level', frp")
	
	*SOC
	areg  stanf_taks_soc post_share_students share_students  post stanf_socialstu_2004_y*_g*  _I* _g*  enroll* if  frp_s == 1 &  regular_hs == 1  & course_type == "soc" [pw  = weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, level `level', frp")
 	
	
    *NOT FRP
	
	***MATH --> TAKS MATH
	areg taks_sd_scale_min_math post_share_students share_students  post taks_math_2004_y*_g* _I* _g*  enroll* if frp_s == 0 & regular_hs == 1 & course_type == "math" [pw= weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students share_students  using teachers_share_pooled, excel dec(3) nocons ctitle("Math, level `level', not frp")
    
	***ENGLISH --> STANFORD LANGUAGE***
	areg stanford_sd_lang_scale  post_share_students share_students  post  stanf_lang_2004_y*_g* _I* _g*  enroll* if  frp_s == 0 &  regular_hs == 1 & course_type == "eng" [pw = weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students share_students  using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, level `level', not frp")

	***SCIENCE - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	areg  stanf_taks_sci  post_share_students share_students post stanf_science_2004_y*_g*  _I* _g*  enroll* if frp_s == 0 & regular_hs == 1  & course_type == "sci" [pw = weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, level `level', not frp")
	
	*SOC
	areg  stanf_taks_soc post_share_students share_students  post stanf_socialstu_2004_y*_g*  _I* _g*  enroll* if  frp_s == 0 &  regular_hs == 1  & course_type == "soc" [pw  = weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, level `level', not frp")
 	

	
	***TEACHER LEVEL - FRP***
	local level = "t"
	
	
	*ABOVE MED FRP
	
	***MATH --> TAKS MATH
	areg taks_sd_scale_min_math post_share_students share_students  post taks_math_2004_y*_g* _I* _g*  enroll* if frp_`level'mean > frp_`level'med  & regular_hs == 1 & course_type == "math" [pw= weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students share_students  using teachers_share_pooled, excel dec(3) nocons ctitle("Math, level `level', above med frp")
    
	***ENGLISH --> STANFORD LANGUAGE***
	areg stanford_sd_lang_scale  post_share_students share_students  post  stanf_lang_2004_y*_g* _I* _g*  enroll* if frp_`level'mean > frp_`level'med&  regular_hs == 1 & course_type == "eng" [pw = weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students share_students  using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, level `level', above med frp")

	***SCIENCE - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	areg  stanf_taks_sci  post_share_students share_students post stanf_science_2004_y*_g*  _I* _g*  enroll* if frp_`level'mean > frp_`level'med & regular_hs == 1  & course_type == "sci" [pw = weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, level `level', above med frp")
	
	*SOC
	areg  stanf_taks_soc post_share_students share_students  post stanf_socialstu_2004_y*_g*  _I* _g*  enroll* if  frp_`level'mean > frp_`level'med &  regular_hs == 1  & course_type == "soc" [pw  = weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, level `level', above med frp")
 	    *NOT FRP
	
	***MATH --> TAKS MATH
	areg taks_sd_scale_min_math post_share_students share_students  post taks_math_2004_y*_g* _I* _g*  enroll* if frp_`level'mean <= frp_`level'med & regular_hs == 1 & course_type == "math" [pw= weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students share_students  using teachers_share_pooled, excel dec(3) nocons ctitle("Math, level `level', below med frp")
    
	***ENGLISH --> STANFORD LANGUAGE***
	areg stanford_sd_lang_scale  post_share_students share_students  post  stanf_lang_2004_y*_g* _I* _g*  enroll* if  frp_`level'mean <= frp_`level'med &  regular_hs == 1 & course_type == "eng" [pw = weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students share_students  using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, level `level', below med frp")

	***SCIENCE - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	areg  stanf_taks_sci  post_share_students share_students post stanf_science_2004_y*_g*  _I* _g*  enroll* if frp_`level'mean <= frp_`level'med & regular_hs == 1  & course_type == "sci" [pw = weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, level `level', below med frp")
	
	*SOC
	areg  stanf_taks_soc post_share_students share_students  post stanf_socialstu_2004_y*_g*  _I* _g*  enroll* if  frp_`level'mean <= frp_`level'med &  regular_hs == 1  & course_type == "soc" [pw  = weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, level `level', below med frp")
 	

   
	***CAMPUS LEVEL - FRP***
	local level = "c"
	
	
	*ABOVE MED FRP
	
	***MATH --> TAKS MATH
	areg taks_sd_scale_min_math post_share_students share_students  post taks_math_2004_y*_g* _I* _g*  enroll* if frp_`level'mean > frp_`level'med  & regular_hs == 1 & course_type == "math" [pw= weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students share_students  using teachers_share_pooled, excel dec(3) nocons ctitle("Math, level `level', above med frp")
    
	***ENGLISH --> STANFORD LANGUAGE***
	areg stanford_sd_lang_scale  post_share_students share_students  post  stanf_lang_2004_y*_g* _I* _g*  enroll* if frp_`level'mean > frp_`level'med&  regular_hs == 1 & course_type == "eng" [pw = weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students share_students  using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, level `level', above med frp")

	***SCIENCE - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	areg  stanf_taks_sci  post_share_students share_students post stanf_science_2004_y*_g*  _I* _g*  enroll* if frp_`level'mean > frp_`level'med & regular_hs == 1  & course_type == "sci" [pw = weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, level `level', above med frp")
	
	*SOC
	areg  stanf_taks_soc post_share_students share_students  post stanf_socialstu_2004_y*_g*  _I* _g*  enroll* if  frp_`level'mean > frp_`level'med &  regular_hs == 1  & course_type == "soc" [pw  = weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, level `level', above med frp")
 	

    *NOT FRP
	
	***MATH --> TAKS MATH
	areg taks_sd_scale_min_math post_share_students share_students  post taks_math_2004_y*_g* _I* _g*  enroll* if frp_`level'mean <= frp_`level'med & regular_hs == 1 & course_type == "math" [pw= weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students share_students  using teachers_share_pooled, excel dec(3) nocons ctitle("Math, level `level', below med frp")
    
	***ENGLISH --> STANFORD LANGUAGE***
	areg stanford_sd_lang_scale  post_share_students share_students  post  stanf_lang_2004_y*_g* _I* _g*  enroll* if  frp_`level'mean <= frp_`level'med &  regular_hs == 1 & course_type == "eng" [pw = weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students share_students  using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, level `level', below med frp")

	***SCIENCE - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	areg  stanf_taks_sci  post_share_students share_students post stanf_science_2004_y*_g*  _I* _g*  enroll* if frp_`level'mean <= frp_`level'med & regular_hs == 1  & course_type == "sci" [pw = weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, level `level', below med frp")
	
	*SOC
	areg  stanf_taks_soc post_share_students share_students  post stanf_socialstu_2004_y*_g*  _I* _g*  enroll* if  frp_`level'mean <= frp_`level'med &  regular_hs == 1  & course_type == "soc" [pw  = weight], cluster(campus) absorb(school_year) 
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, level `level', below med frp")


*ESTIMATE MODELS THAT USE ONLY "ACROSS TEACHER" AND NOT "WITHIN TEACHER" VARIATION BY USING 1/#Teachers in dept IN 2004-05 instead of share; School FE Only
	use temp, clear
	xi i.grade*i.year, prefix(_g)
	xi i.female i.ethnicity i.econdis i.atrisk i.speced i.lep i.gifted 
	xi i.campus, prefix(_c)
	
	gen mean_share_math_2004a = 1/teachers_grade_math if course_type == "math" & year == 2004
	egen mean_share_math_2004 = mean(mean_share_math_2004a) if course_type == "math", by(campus grade) 
	
	gen mean_share_eng_2004a = 1/teachers_grade_eng  if course_type == "eng" & year == 2004
	egen mean_share_eng_2004 = mean(mean_share_eng_2004a) if course_type == "eng" , by(campus grade) 
		
	gen mean_share_sci_2004a = 1/teachers_grade_sci  if course_type == "sci" & year == 2004
	egen mean_share_sci_2004 = mean(mean_share_sci_2004a)  if course_type == "sci", by(campus grade)
	
	gen mean_share_soc_2004a = 1/teachers_grade_soc  if course_type == "soc" & year == 2004
	egen mean_share_soc_2004 = mean(mean_share_soc_2004a) if course_type == "soc", by(campus grade) 
	
	gen post_mean_share_math_2004 = post*mean_share_math_2004
	gen post_mean_share_eng_2004 = post*mean_share_eng_2004
	gen post_mean_share_sci_2004 = post*mean_share_sci_2004
	gen post_mean_share_soc_2004 = post*mean_share_soc_2004

	***MATH --> TAKS MATH
	reg taks_sd_scale_min_math post_mean_share_math_2004 mean_share_math_2004  post taks_math_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "math" [pw = weight], cluster(campus)
	outreg2 post_mean_share_math_2004 mean_share_math_2004   using teachers_share_pooled, excel dec(3) nocons ctitle("Math, No School FE, pre-aspire share, redform")
	areg taks_sd_scale_min_math post_mean_share_math_2004 mean_share_math_2004  post taks_math_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "math" [pw = weight], cluster(campus) absorb(school)
	outreg2 post_mean_share_math_2004 mean_share_math_2004   using teachers_share_pooled, excel dec(3) nocons ctitle("Math, School FE, pre-aspire share, redform")
	
	reg post_share_students post_mean_share_math_2004   mean_share_math_2004 post taks_math_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "math" [pw = weight], cluster(campus)
	outreg2 post_mean_share_math_2004  mean_share_math_2004  using teachers_share_pooled, excel dec(3) nocons ctitle("Math, No School FE, pre-aspire share, FS-postshare")
	reg  share_students post_mean_share_math_2004  mean_share_math_2004 post taks_math_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "math" [pw = weight], cluster(campus) 
	outreg2 post_mean_share_math_2004  mean_share_math_2004  using teachers_share_pooled, excel dec(3) nocons ctitle("Math, No School FE, pre-aspire share, FS-share")
	
	
	ivreg taks_sd_scale_min_math (post_share_students share_students = post_mean_share_math_2004 mean_share_math_2004)  post taks_math_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "math" [pw = weight], cluster(campus) first
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Math, No School FE, pre-aspire share, 2SLS")

	***ENGLISH --> STANFORD LANGUAGE***
	reg stanford_sd_lang_scale post_mean_share_eng_2004 mean_share_eng_2004  post stanf_lang_2004_y*_g*  _I* _g* enroll* if regular_hs == 1  & course_type == "eng" [pw = weight], cluster(campus)
	outreg2 post_mean_share_eng_2004 mean_share_eng_2004   using teachers_share_pooled, excel dec(3) nocons ctitle("eng, No School FE, pre-aspire share, redform")
	areg stanford_sd_lang_scale post_mean_share_eng_2004 mean_share_eng_2004  post stanf_lang_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "eng" [pw = weight], cluster(campus) absorb(school)
	outreg2 post_mean_share_eng_2004 mean_share_eng_2004   using teachers_share_pooled, excel dec(3) nocons ctitle("eng, School FE, pre-aspire share, redform")
	
	reg post_share_students post_mean_share_eng_2004  mean_share_eng_2004 post stanf_lang_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "eng" [pw = weight], cluster(campus)
	outreg2 post_mean_share_eng_2004  mean_share_eng_2004  using teachers_share_pooled, excel dec(3) nocons ctitle("eng, No School FE, pre-aspire share, FS-postshare")
	reg  share_students post_mean_share_eng_2004 mean_share_eng_2004 post stanf_lang_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "eng" [pw = weight], cluster(campus) 
	outreg2 post_mean_share_eng_2004  mean_share_eng_2004  using teachers_share_pooled, excel dec(3) nocons ctitle("eng, No School FE, pre-aspire share, FS-share")
	

	ivreg stanford_sd_lang_scale (post_share_students share_students = post_mean_share_eng_2004 mean_share_eng_2004)  post stanf_lang_2004_y*_g*  _I* _g* enroll* if regular_hs == 1  & course_type == "eng" [pw = weight], cluster(campus) first
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("eng, No School FE, pre-aspire share, 2SLS")

	***SCI
	reg stanf_taks_sci post_mean_share_sci_2004 mean_share_sci_2004  post stanf_science_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "sci" [pw = weight], cluster(campus)
	outreg2 post_mean_share_sci_2004 mean_share_sci_2004   using teachers_share_pooled, excel dec(3) nocons ctitle("sci, No School FE, pre-aspire share, redform")
	areg stanf_taks_sci post_mean_share_sci_2004 mean_share_sci_2004  post stanf_science_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "sci" [pw = weight], cluster(campus) absorb(school)
	outreg2 post_mean_share_sci_2004 mean_share_sci_2004   using teachers_share_pooled, excel dec(3) nocons ctitle("sci, School FE, pre-aspire share, redform")
	

	reg post_share_students post_mean_share_sci_2004  mean_share_sci_2004 post stanf_science_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "sci" [pw = weight], cluster(campus)
	outreg2 post_mean_share_sci_2004  mean_share_sci_2004  using teachers_share_pooled, excel dec(3) nocons ctitle("sci, No School FE, pre-aspire share, FS-postshare")
	reg  share_students post_mean_share_sci_2004  mean_share_sci_2004 post stanf_science_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "sci" [pw = weight], cluster(campus) 
	outreg2 post_mean_share_sci_2004  mean_share_sci_2004  using teachers_share_pooled, excel dec(3) nocons ctitle("sci, No School FE, pre-aspire share, FS-share")
	
	
	
	ivreg stanf_taks_sci (post_share_students share_students = post_mean_share_sci_2004 mean_share_sci_2004)  post stanf_science_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "sci" [pw = weight], cluster(campus) first
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("sci, No School FE, pre-aspire share, 2SLS")

	***SOC
	reg stanf_taks_soc post_mean_share_soc_2004 mean_share_soc_2004  post stanf_socialstu_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "soc" [pw = weight], cluster(campus)
	outreg2 post_mean_share_soc_2004 mean_share_soc_2004   using teachers_share_pooled, excel dec(3) nocons ctitle("soc, No School FE, pre-aspire share, redform")
	areg stanf_taks_soc post_mean_share_soc_2004 mean_share_soc_2004  post stanf_socialstu_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "soc" [pw = weight], cluster(campus) absorb(school)
	outreg2 post_mean_share_soc_2004 mean_share_soc_2004   using teachers_share_pooled, excel dec(3) nocons ctitle("soc, School FE, pre-aspire share, redform")
	
	reg post_share_students post_mean_share_soc_2004   mean_share_soc_2004 post stanf_socialstu_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "soc" [pw = weight], cluster(campus)
	outreg2 post_mean_share_soc_2004  mean_share_soc_2004  using teachers_share_pooled, excel dec(3) nocons ctitle("soc, No School FE, pre-aspire share, FS-postshare")
	reg  share_students post_mean_share_soc_2004 mean_share_soc_2004 post stanf_socialstu_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "soc" [pw = weight], cluster(campus) 
	outreg2 post_mean_share_soc_2004  mean_share_soc_2004  using teachers_share_pooled, excel dec(3) nocons ctitle("soc, No School FE, pre-aspire share, FS-share")
	
	
	
	ivreg stanf_taks_soc (post_share_students share_students = post_mean_share_soc_2004 mean_share_soc_2004)  post stanf_socialstu_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "soc" [pw = weight], cluster(campus) first
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("soc, No School FE, pre-aspire share, 2SLS")

	***MATH --> Stanf MATH
	reg stanford_sd_math_scale post_mean_share_math_2004 mean_share_math_2004  post stanf_math_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "math" [pw = weight], cluster(campus)
	outreg2 post_mean_share_math_2004 mean_share_math_2004   using teachers_share_pooled, excel dec(3) nocons ctitle("Math Stanf, No School FE, pre-aspire share, redform")
	areg stanford_sd_math_scale post_mean_share_math_2004 mean_share_math_2004  post stanf_math_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "math" [pw = weight], cluster(campus) absorb(school)
	outreg2 post_mean_share_math_2004 mean_share_math_2004   using teachers_share_pooled, excel dec(3) nocons ctitle("Math Stanf, School FE, pre-aspire share, redform")
	
	reg post_share_students post_mean_share_math_2004   mean_share_math_2004 post stanf_math_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "math" [pw = weight], cluster(campus)
	outreg2 post_mean_share_math_2004  mean_share_math_2004  using teachers_share_pooled, excel dec(3) nocons ctitle("Math Stanf No School FE, pre-aspire share, FS-postshare")
	reg  share_students post_mean_share_math_2004  mean_share_math_2004 post stanf_math_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "math" [pw = weight], cluster(campus) 
	outreg2 post_mean_share_math_2004  mean_share_math_2004  using teachers_share_pooled, excel dec(3) nocons ctitle("Math Stanf, No School FE, pre-aspire share, FS-share")
	
	
	ivreg stanford_sd_math_scale (post_share_students share_students = post_mean_share_math_2004 mean_share_math_2004)  post stanf_math_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "math" [pw = weight], cluster(campus) first
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Math Stanf, No School FE, pre-aspire share, 2SLS")

	


*USE TEACHER-YEAR FIXED EFFECTS TO IDENTIFY IMPACTS ACROSS GRADES WITHIN TEACHER (E.G. DO TEACHERS WITH MORE STUDNETS IN A GRADE WORK HARDER IN THAT GRADE?"
	use temp, clear
	xi i.grade*i.year, prefix(_g)
	xi i.female i.ethnicity i.econdis i.atrisk i.speced i.lep i.gifted 
	gen teacher_year = string(tch_number) + string(campus) + string(year)
	
	
	***MATH --> TAKS MATH
	areg taks_sd_scale_min_math post_share_students  share_students  post taks_math_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "math" [pw = weight], cluster(campus) absorb(teacher_year)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Math, School FE, No enter")

	***ENGLISH --> STANFORD LANGUAGE***
	areg stanford_sd_lang_scale  post_share_students  share_students   post  stanf_lang_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "eng" [pw = weight], cluster(campus) absorb(teacher_year)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, School FE, No enter")

	***SCIENCE  - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	areg  stanf_taks_sci  post_share_students  share_students    post stanf_science_2004_y*_g* _I* _g* enroll* if regular_hs == 1 &  course_type == "sci" [pw = weight], cluster(campus) absorb(teacher_year)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, School FE, No enter")

	***SOC
	areg  stanf_taks_soc post_share_students  share_students   post stanf_socialstu_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "soc" [pw = weight], cluster(campus) absorb(teacher_year)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, School FE, No enter")
	
	***MATH - STANF
	areg stanford_sd_math_scale post_share_students  share_students  _I* _g* enroll* stanf_math_2004_y*_g*  if regular_hs == 1 &  course_type == "math" [pw = weight], cluster(campus) absorb(teacher_year)
	outreg2 post_share_students  share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Math - Stanf, School FE, , No enter ")

	
*ESTIMATE PERSISTENCE EFFECTS
	
	***MATH --> TAKS MATH
	use temp, clear
	sort id year
	merge id year using math_persist, nokeep
	keep if lshare_students != .
	keep if grade >= 10
	xi i.grade*i.year, prefix(_g)
	xi i.female i.ethnicity i.econdis i.atrisk i.speced i.lep i.gifted 	

		*w/o lag
		areg taks_sd_scale_min_math post_share_students  share_students  post taks_math_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "math" [pw = weight], cluster(campus) absorb(school_year)
		outreg2 post_share_students  share_students  using teachers_share_pooled, excel dec(3) nocons ctitle("Math, School FE, persist")
		
		*w/ lag
		areg taks_sd_scale_min_math post_share_students  lpost_share_students share_students  lshare_students  post taks_math_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "math" [pw = weight], cluster(campus) absorb(school_year)
		outreg2 post_share_students  lpost_share_students share_students  lshare_students using teachers_share_pooled, excel dec(3) nocons ctitle("Math, School FE, persist")

		
		
	***ENGLISH --> STANFORD LANGUAGE***
	use temp, clear
	sort id year
	merge id year using eng_persist, nokeep
	keep if lshare_students != .
	keep if grade >= 10
	xi i.grade*i.year, prefix(_g)
	xi i.female i.ethnicity i.econdis i.atrisk i.speced i.lep i.gifted 	

	*w/o lag
	areg stanford_sd_lang_scale  post_share_students   share_students     post  stanf_lang_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "eng" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students     using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, School FE, persist")

	*w/ lag
	areg stanford_sd_lang_scale  post_share_students  lpost_share_students share_students  lshare_students   post  stanf_lang_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "eng" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  lpost_share_students share_students  lshare_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, School FE, persist")

	
	***SCIENCE  - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	use temp, clear
	sort id year
	merge id year using sci_persist, nokeep
	keep if lshare_students != .
	keep if grade >= 10
	xi i.grade*i.year, prefix(_g)
	xi i.female i.ethnicity i.econdis i.atrisk i.speced i.lep i.gifted 	

	*w/o lag
	areg  stanf_taks_sci  post_share_students   share_students      post stanf_science_2004_y*_g* _I* _g* enroll* if regular_hs == 1 &  course_type == "sci" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students   share_students    using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, School FE, persist")

	*w/ lag
	areg  stanf_taks_sci  post_share_students  lpost_share_students share_students  lshare_students    post stanf_science_2004_y*_g* _I* _g* enroll* if regular_hs == 1 &  course_type == "sci" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  lpost_share_students share_students  lshare_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, School FE, persist")
	
	

	***SOC
	use temp, clear
	sort id year
	merge id year using soc_persist, nokeep
	keep if lshare_students != .
	keep if grade >= 10
	xi i.grade*i.year, prefix(_g)
	xi i.female i.ethnicity i.econdis i.atrisk i.speced i.lep i.gifted 	

	*w/o lag
	areg  stanf_taks_soc post_share_students   share_students     post stanf_socialstu_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "soc" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students   share_students     using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, School FE, persist")
	
	*w/ lag
	areg  stanf_taks_soc post_share_students  lpost_share_students share_students  lshare_students   post stanf_socialstu_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "soc" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  lpost_share_students share_students  lshare_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, School FE, persist")
		
		
		
	
	***MATH - STANF
	use temp, clear
	sort id year
	merge id year using math_persist, nokeep
	keep if lshare_students != .
	keep if grade >= 10
	xi i.grade*i.year, prefix(_g)
	xi i.female i.ethnicity i.econdis i.atrisk i.speced i.lep i.gifted 	

	*w/o lag
	areg stanford_sd_math_scale post_share_students   share_students    _I* _g* enroll* stanf_math_2004_y*_g*  if regular_hs == 1 &  course_type == "math" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students   share_students     using teachers_share_pooled, excel dec(3) nocons ctitle("Math - Stanf, School FE, persist ")
	
	*w/ lag
	areg stanford_sd_math_scale post_share_students  lpost_share_students share_students  lshare_students  _I* _g* enroll* stanf_math_2004_y*_g*  if regular_hs == 1 &  course_type == "math" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  lpost_share_students share_students  lshare_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Math - Stanf, School FE, persist ")

	





*IMPACT VARIATION BY PLACE IN PRIOR-YEAR'S VALUE-ADDED DISTRIBUTION
use temp, clear
gen nextyear = year
sort campus nextyear grade course_type
merge campus nextyear grade course_type using percentile_rankings.dta, keep(cgi group_percentile)

  *GENERATE DECILES OF PRIOR YEAR DISTRIBUTION
  gen group_decile_1 = group_percentile >= 0 & group_percentile < 10
  gen group_decile_2 = group_percentile >= 10 & group_percentile < 20
  gen group_decile_3 = group_percentile >= 20 & group_percentile < 30
  gen group_decile_4 = group_percentile >= 30 & group_percentile < 40
  gen group_decile_5 = group_percentile >= 40 & group_percentile < 50
  gen group_decile_6 = group_percentile >= 50 & group_percentile < 60
  gen group_decile_7 = group_percentile >= 60 & group_percentile < 70
  gen group_decile_8 = group_percentile >= 70 & group_percentile < 80
  gen group_decile_9 = group_percentile >= 80 & group_percentile < 90
  gen group_decile_10 = group_percentile >= 90 & group_percentile <100
  
  forvalue decile = 1/10 {
	gen post_share_students_dec`decile' = post_share_students*group_decile_`decile'
  }
  
  
	***MATH --> TAKS MATH
	areg taks_sd_scale_min_math post_share_students_dec*  share_students group_decile_* post taks_math_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "math" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students_dec*  share_students group_decile_* using teachers_share_pooled, excel dec(3) nocons ctitle("Math, School FE, VA Deciles")

	***ENGLISH --> STANFORD LANGUAGE***
	areg stanford_sd_lang_scale  post_share_students_dec*  share_students group_decile_*    post  stanf_lang_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "eng" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students_dec*  share_students group_decile_*    using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, School FE, VA Deciles")

	***SCIENCE  - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	areg  stanf_taks_sci  post_share_students_dec*  share_students group_decile_*     post stanf_science_2004_y*_g* _I* _g* enroll* if regular_hs == 1 &  course_type == "sci" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students_dec*  share_students group_decile_*    using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, School FE, VA Deciles")

	***SOC
	areg  stanf_taks_soc post_share_students_dec*  share_students group_decile_*    post stanf_socialstu_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "soc" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students_dec*  share_students group_decile_*    using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, School FE, VA Deciles")
	
	***MATH - STANF
	areg stanford_sd_math_scale post_share_students_dec*  share_students group_decile_*   _I* _g* enroll* stanf_math_2004_y*_g*  if regular_hs == 1 &  course_type == "math" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students_dec*  share_students group_decile_*    using teachers_share_pooled, excel dec(3) nocons ctitle("Math - Stanf, School FE, , VA Deciles ")

  
  
	





*MAIN EFFECTS FOR LARGE AND SMALL DEPARTMENTS 
	use temp, clear
	xi i.grade*i.year, prefix(_g)
	xi i.female i.ethnicity i.econdis i.atrisk i.speced i.lep i.gifted 
	
	*INTERACT "POST" WITH DEPARTMENT SIZE
	gen dept_size_small_math = teachers_grade_math <= 10 if teachers_grade_math != .
	gen dept_size_med_math = teachers_grade_math > 10 & teachers_grade_math <= 20 if teachers_grade_math != .
	gen dept_size_large_math = teachers_grade_math > 20 if teachers_grade_math != .
	gen post_dept_size_small_math = post*dept_size_small_math
	gen post_dept_size_med_math = post*dept_size_med_math
	gen post_dept_size_large_math = post*dept_size_large_math

	gen dept_size_small_eng = teachers_grade_eng <= 10 if teachers_grade_eng != .
	gen dept_size_med_eng = teachers_grade_eng > 10 & teachers_grade_eng <= 20 if teachers_grade_eng != .
	gen dept_size_large_eng = teachers_grade_eng > 20 if teachers_grade_eng != .
	gen post_dept_size_small_eng = post*dept_size_small_eng
	gen post_dept_size_med_eng = post*dept_size_med_eng
	gen post_dept_size_large_eng = post*dept_size_large_eng

	gen dept_size_small_sci = teachers_grade_sci <= 10 if teachers_grade_sci != .
	gen dept_size_med_sci = teachers_grade_sci > 10 & teachers_grade_sci <= 20 if teachers_grade_sci != .
	gen dept_size_large_sci = teachers_grade_sci > 20 if teachers_grade_sci != .
	gen post_dept_size_small_sci = post*dept_size_small_sci
	gen post_dept_size_med_sci = post*dept_size_med_sci
	gen post_dept_size_large_sci = post*dept_size_large_sci

	gen dept_size_small_soc = teachers_grade_soc <= 10 if teachers_grade_soc != .
	gen dept_size_med_soc = teachers_grade_soc > 10 & teachers_grade_soc <= 20 if teachers_grade_soc != .
	gen dept_size_large_soc = teachers_grade_soc > 20 if teachers_grade_soc != .
	gen post_dept_size_small_soc = post*dept_size_small_soc
	gen post_dept_size_med_soc = post*dept_size_med_soc
	gen post_dept_size_large_soc = post*dept_size_large_soc

	
	***MATH --> TAKS MATH
	areg taks_sd_scale_min_math  post_dept_size_med_math post_dept_size_large_math dept_size_med_math dept_size_large_math post taks_math_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "math" [pw = weight], cluster(campus) absorb(campus)
	outreg2 post_dept_size_med_math post_dept_size_large_math dept_size_med_math dept_size_large_math    using teachers_share_pooled, excel dec(3) nocons ctitle("Math, School FE, main effects by dept size")
	
	***ENGLISH --> STANFORD LANGUAGE***
	areg stanford_sd_lang_scale  post_dept_size_med_eng post_dept_size_large_eng dept_size_med_eng dept_size_large_eng   post  stanf_lang_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "eng" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_dept_size_med_eng post_dept_size_large_eng dept_size_med_eng dept_size_large_eng   using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, School FE, main effects by dept size")

	***SCIENCE  - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	areg  stanf_taks_sci  post_dept_size_med_sci post_dept_size_large_sci dept_size_med_sci dept_size_large_sci     post stanf_science_2004_y*_g* _I* _g* enroll* if regular_hs == 1 &  course_type == "sci" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_dept_size_med_sci post_dept_size_large_sci dept_size_med_sci dept_size_large_sci    using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, School FE, main effects by dept size")

	***SOC
	areg  stanf_taks_soc post_dept_size_med_soc post_dept_size_large_soc dept_size_med_soc dept_size_large_soc    post stanf_socialstu_2004_y*_g* _I* _g* enroll* if regular_hs == 1  & course_type == "soc" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_dept_size_med_soc post_dept_size_large_soc dept_size_med_soc dept_size_large_soc    using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, School FE, main effects by dept size")
	
	***MATH - STANF
	areg stanford_sd_math_scale post_dept_size_med_math post_dept_size_large_math dept_size_med_math dept_size_large_math   _I* _g* enroll* stanf_math_2004_y*_g*  if regular_hs == 1 &  course_type == "math" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_dept_size_med_math post_dept_size_large_math dept_size_med_math dept_size_large_math    using teachers_share_pooled, excel dec(3) nocons ctitle("Math - Stanf, School FE, , main effects by dept size ")

	
		
*SEPARATE ESTIMATES FOR ABOVE/BELOW 0.15 SHARE
	use temp, clear
	xi i.grade*i.year, prefix(_g)
	xi i.female i.ethnicity i.econdis i.atrisk i.speced i.lep i.gifted i.campus*i.year

	**SUEST COMMAND DOES NOT WORK WITH PWEIGHTS SO MUST USE AWEIGHTS	
	
	**SET CUTOFF
	local cutoff = 0.15
	
	*LIMIT TO SHARES BELOW 0.4
	keep if share_students < 0.4
	
	**BELOW 
	
	***MATH --> TAKS MATH

	reg taks_sd_scale_min_math post_share_students share_students post taks_math_2004_y*_g* _I* _g* enroll* if share_students <= `cutoff' & regular_hs == 1 & course_type == "math" [aw= weight]
	estimates store below_math
	
	reg taks_sd_scale_min_math post_share_students share_students post taks_math_2004_y*_g* _I* _g* enroll* if share_students <= `cutoff' & regular_hs == 1 & course_type == "math" [aw= weight], cluster(campus)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Math, School FE, Below `cutoff'")
    
	***ENGLISH --> STANFORD LANGUAGE***
	reg stanford_sd_lang_scale  post_share_students share_students  post  stanf_lang_2004_y*_g* _I* _g* enroll* if share_students <= `cutoff' &  regular_hs == 1 & course_type == "eng" [aw = weight]
	estimates store below_eng
	reg stanford_sd_lang_scale  post_share_students share_students  post  stanf_lang_2004_y*_g* _I* _g* enroll* if share_students <= `cutoff' &  regular_hs == 1 & course_type == "eng" [aw = weight], cluster(campus)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, School FE, Below `cutoff'")

	***SCIENCE - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	reg  stanf_taks_sci  post_share_students share_students  post stanf_science_2004_y*_g*  _I* _g* enroll* if share_students <= `cutoff' &  regular_hs == 1  & course_type == "sci" [aw = weight]
	estimates store below_sci
	reg  stanf_taks_sci  post_share_students share_students  post stanf_science_2004_y*_g*  _I* _g* enroll* if share_students <= `cutoff' &  regular_hs == 1  & course_type == "sci" [aw = weight], cluster(campus)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, School FE, Below `cutoff'")
	
	*SOC
	reg  stanf_taks_soc post_share_students share_students post stanf_socialstu_2004_y*_g*  _I* _g* enroll* if  share_students <= `cutoff' &  regular_hs == 1  & course_type == "soc" [aw  = weight]
	estimates store below_soc
	reg  stanf_taks_soc post_share_students share_students post stanf_socialstu_2004_y*_g*  _I* _g* enroll* if  share_students <= `cutoff' &  regular_hs == 1  & course_type == "soc" [aw  = weight], cluster(campus)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, School FE, Below `cutoff'")
 	
	***MATH - STANF
	reg stanford_sd_math_scale post_share_students share_students post stanf_math_2004_y*_g*  _I* _g* enroll* if share_students <= `cutoff' &  regular_hs == 1 & course_type == "math" [aw  = weight]
	estimates store below_stanf	
	reg stanford_sd_math_scale post_share_students share_students post stanf_math_2004_y*_g*  _I* _g* enroll* if share_students <= `cutoff' &  regular_hs == 1 & course_type == "math" [aw  = weight], cluster(campus)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Math - Stanf, School FE, Below `cutoff'")
   
	*ABOVE
	
	***MATH --> TAKS MATH
	reg taks_sd_scale_min_math post_share_students share_students post taks_math_2004_y*_g* _I* _g* enroll* if share_students > `cutoff' & regular_hs == 1 & course_type == "math" [aw = weight]
	estimates store above_math
	reg taks_sd_scale_min_math post_share_students share_students post taks_math_2004_y*_g* _I* _g* enroll* if share_students > `cutoff' & regular_hs == 1 & course_type == "math" [aw = weight], cluster(campus)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Math, School FE, Above `cutoff'")
    	

	***ENGLISH --> STANFORD LANGUAGE***
 	reg stanford_sd_lang_scale  post_share_students share_students  post  stanf_lang_2004_y*_g* _I* _g* enroll* if share_students > `cutoff' &  regular_hs == 1 & course_type == "eng" [aw  = weight]
	estimates store above_eng
 	reg stanford_sd_lang_scale  post_share_students share_students  post  stanf_lang_2004_y*_g* _I* _g* enroll* if share_students > `cutoff' &  regular_hs == 1 & course_type == "eng" [aw  = weight], cluster(campus)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, School FE, Above `cutoff'")
	
	***SCIENCE - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	reg  stanf_taks_sci  post_share_students share_students  post stanf_science_2004_y*_g*  _I* _g* enroll* if share_students > `cutoff' &  regular_hs == 1  & course_type == "sci" [aw  = weight]
	estimates store above_sci
	reg  stanf_taks_sci  post_share_students share_students  post stanf_science_2004_y*_g*  _I* _g* enroll* if share_students > `cutoff' &  regular_hs == 1  & course_type == "sci" [aw  = weight], cluster(campus)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, School FE, Above `cutoff'")

	***SOC 
	reg  stanf_taks_soc post_share_students share_students post stanf_socialstu_2004_y*_g*  _I* _g* enroll* if  share_students > `cutoff' &  regular_hs == 1  & course_type == "soc" [aw = weight]
	estimates store above_soc
	reg  stanf_taks_soc post_share_students share_students post stanf_socialstu_2004_y*_g*  _I* _g* enroll* if  share_students > `cutoff' &  regular_hs == 1  & course_type == "soc" [aw = weight], cluster(campus)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, School FE, Above `cutoff'")
  	 	
	***MATH - STANF
	reg stanford_sd_math_scale post_share_students share_students post stanf_math_2004_y*_g*  _I* _g* enroll* if share_students > `cutoff' &  regular_hs == 1 & course_type == "math" [aw  = weight]
	estimates store above_stanf
 	reg stanford_sd_math_scale post_share_students share_students post stanf_math_2004_y*_g*  _I* _g* enroll* if share_students > `cutoff' &  regular_hs == 1 & course_type == "math" [aw  = weight], cluster(campus)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Math - Stanf, School FE, Above `cutoff'")

	
	*TEST ABOVE VS BELOW
	
	foreach subject in "math" "eng" "sci" "soc" "stanf" {
		suest below_`subject' above_`subject', vce(cluster campus)
		test [below_`subject'_mean]post_share_students = [above_`subject'_mean]post_share_students
		test [below_`subject'_mean]share_students = [above_`subject'_mean]share_students
}



*ESTIMATES FOR OTHER NON-INCENTIVIZED EXAMS
	use temp, clear
	xi i.grade*i.year, prefix(_g)
	xi i.female i.ethnicity i.econdis i.atrisk i.speced i.lep i.gifted

	***STANFORD MATH
	areg stanford_sd_math_scale  post_share_students share_students  post  stanf_math_2004_y*_g* _I* _g* enroll* if regular_hs == 1 & course_type == "math" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Math, Non-Inct Exams, Stanf Math")

	***READING FOR ENGLISH TEACHERS
	areg stanford_sd_read_scale  post_share_students share_students  post  stanf_lang_2004_y*_g* _I* _g* enroll* if regular_hs == 1 & course_type == "eng" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, Non-Inct Exams, Stanf Reading")

  	***science 10th & 11th grade
	areg stanford_sd_science_scale  post_share_students share_students  post  stanf_science_2004_y*_g* _I* _g* enroll* if regular_hs == 1 & course_type == "sci"  & (grade == 10 | grade == 11) [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("SCI, Non-Inct Exams, Stanf Sci 10th 11th")

  	***soc 10th & 11th grade
	areg stanford_sd_socialstu_scale  post_share_students share_students  post  stanf_socialstu_2004_y*_g* _I* _g* enroll* if regular_hs == 1 & course_type == "soc"  & (grade == 10 | grade == 11) [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("soc, Non-Inct Exams, Stanf soc 10th 11th")
  
	***compare to science 9th grade
	areg stanford_sd_science_scale  post_share_students share_students  post  stanf_science_2004_y*_g* _I* _g* enroll* if regular_hs == 1 & course_type == "sci"  & (grade == 9) [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("SCI, Inct Exams, Stanf Sci 9th")

	*** compare to soc 9th grade
	areg stanford_sd_socialstu_scale  post_share_students share_students  post  stanf_socialstu_2004_y*_g* _I* _g* enroll* if regular_hs == 1 & course_type == "soc"  & (grade == 9) [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students share_students using teachers_share_pooled, excel dec(3) nocons ctitle("soc, Inct Exams, Stanf soc 9th")  
  
  
  
  
  
   ***TESTS OF ABOVE VS BELOW MEDIAN***
    
		local level = "s"

		*MATH
		xi i.grade*i.year, prefix(_g)
		xi i.female i.ethnicity i.econdis i.atrisk i.speced i.lep i.gifted
		xi i.campus*i.year, prefix(_c)
	 
		reg taks_sd_scale_min_math post_share_students  post taks_math_2004_y*_g* _I* _g*  enroll* _c* if lstanford_sd_math_scale < math_`level'med & regular_hs == 1 & course_type == "math" [pw= weight]
		estimates store below
		reg taks_sd_scale_min_math post_share_students  post taks_math_2004_y*_g* _I* _g* _c* enroll*  if lstanford_sd_math_scale >= math_`level'med & regular_hs == 1 & course_type == "math" [pw= weight]
		estimates store above
		suest below above, vce(cluster school_year)
		test [below_mean]post_share = [above_mean]post_share
 
 
 		*LANG
		reg stanford_sd_lang_scale  post_share_students  post  stanf_lang_2004_y*_g* _I* _g* _c* enroll* if  lstanford_sd_lang_scale < lang_`level'med &  regular_hs == 1 & course_type == "eng" [iw = weight]
		estimates store below
		reg stanford_sd_lang_scale  post_share_students  post  stanf_lang_2004_y*_g* _I* _g* _c* enroll* if  lstanford_sd_lang_scale >= lang_`level'med &  regular_hs == 1 & course_type == "eng" [iw = weight] 
		estimates store above
		suest below above, vce(cluster school_year)
		test [below_mean]post_share = [above_mean]post_share
		
		
  		*SCI
		reg  stanf_taks_sci  post_share_students post stanf_science_2004_y*_g*  _I* _g* _c* enroll* if lstanford_sd_science_scale < sci_`level'med & regular_hs == 1  & course_type == "sci" [iw = weight] 
		estimates store below
		reg  stanf_taks_sci  post_share_students post stanf_science_2004_y*_g*  _I* _g* _c* enroll* if lstanford_sd_science_scale >= sci_`level'med & regular_hs == 1  & course_type == "sci" [iw = weight] 
		estimates store above
		suest below above, vce(cluster school_year)
		test [below_mean]post_share = [above_mean]post_share
		
  		*SOC
		reg  stanf_taks_soc post_share_students  post stanf_socialstu_2004_y*_g*  _I* _g* _c* enroll* if  lstanford_sd_socialstu_scale < soc_`level'med &  regular_hs == 1  & course_type == "soc" [iw = weight] 
		estimates store below
		reg  stanf_taks_soc post_share_students  post stanf_socialstu_2004_y*_g*  _I* _g* _c* enroll* if  lstanford_sd_socialstu_scale >= soc_`level'med &  regular_hs == 1  & course_type == "soc" [iw = weight] 
		estimates store above
		suest below above, vce(cluster school_year)
		test [below_mean]post_share = [above_mean]post_share
		
		*MATH - STANF
		reg stanford_sd_math_scale post_share_students  post stanf_math_2004_y*_g*  _I* _g* _c* enroll* if  lstanford_sd_math_scale < math_`level'med &  regular_hs == 1 & course_type == "math" [iw = weight] 
		estimates store below
		reg stanford_sd_math_scale post_share_students  post stanf_math_2004_y*_g*  _I* _g* _c* enroll* if  lstanford_sd_math_scale >= math_`level'med &  regular_hs == 1 & course_type == "math" [iw = weight] 
		estimates store above
		suest below above, vce(cluster school_year)
		test [below_mean]post_share = [above_mean]post_share
		
				
		
		
	
   
   ***TESTS OF ABOVE VS BELOW MEDIAN***
     
		*MATH
		reg taks_sd_scale_min_math post_share_students  post taks_math_2004_y*_g* _I* _g* _c* enroll* if frp_s == 1 & regular_hs == 1 & course_type == "math" [iw= weight]
		estimates store frp
		reg taks_sd_scale_min_math post_share_students  post taks_math_2004_y*_g* _I* _g* _c* enroll* if frp_s == 0 & regular_hs == 1 & course_type == "math" [iw= weight]
		estimates store nofrp
		suest frp nofrp, vce(cluster school_year)
		test [frp_mean]post_share = [nofrp_mean]post_share
 
 
 		*LANG
		reg stanford_sd_lang_scale  post_share_students  post  stanf_lang_2004_y*_g* _I* _g* _c* enroll* if  frp_s == 1 &  regular_hs == 1 & course_type == "eng" [iw = weight] 
		estimates store frp
		reg stanford_sd_lang_scale  post_share_students  post  stanf_lang_2004_y*_g* _I* _g* _c* enroll* if  frp_s == 0 & regular_hs == 1 & course_type == "eng" [iw = weight] 
		estimates store nofrp
		suest frp nofrp, vce(cluster school_year)
		test [frp_mean]post_share = [nofrp_mean]post_share
 
 
  		*SCI
		reg  stanf_taks_sci  post_share_students post stanf_science_2004_y*_g*  _I* _g* _c* enroll* if frp_s == 1 & regular_hs == 1  & course_type == "sci" [iw = weight] 
		estimates store frp
		reg  stanf_taks_sci  post_share_students post stanf_science_2004_y*_g*  _I* _g* _c* enroll* if frp_s == 0 & regular_hs == 1  & course_type == "sci" [iw = weight] 
		estimates store nofrp
		suest frp nofrp, vce(cluster school_year)
		test [frp_mean]post_share = [nofrp_mean]post_share
 
 
  		*SOC
		reg  stanf_taks_soc post_share_students  post stanf_socialstu_2004_y*_g*  _I* _g* _c* enroll* if  frp_s == 1 &  regular_hs == 1  & course_type == "soc" [iw = weight] 
		estimates store frp
		reg  stanf_taks_soc post_share_students  post stanf_socialstu_2004_y*_g*  _I* _g* _c* enroll* if  frp_s == 0 &  regular_hs == 1  & course_type == "soc" [iw = weight] 
		estimates store nofrp
		suest frp nofrp, vce(cluster school_year)
		test [frp_mean]post_share = [nofrp_mean]post_share
 
 
		*MATH - STANF
		reg stanford_sd_math_scale post_share_students  post stanf_math_2004_y*_g*  _I* _g* _c* enroll* if  frp_s == 1 &  regular_hs == 1 & course_type == "math" [iw = weight] 
		estimates store frp
		reg stanford_sd_math_scale post_share_students  post stanf_math_2004_y*_g*  _I* _g* _c* enroll* if  frp_s == 0 & regular_hs == 1 & course_type == "math" [iw = weight] 
		estimates store nofrp
		suest frp nofrp, vce(cluster school_year)
		test [frp_mean]post_share = [nofrp_mean]post_share
 
 


***CONTROL FOR TRACKING**
	use temp, clear
	xi i.grade*i.year, prefix(_g)
	xi i.female i.ethnicity i.econdis i.atrisk i.speced i.lep i.gifted 

	***MATH --> TAKS MATH
	areg taks_sd_scale_min_math post_share_students  share_students  stanf_math_peer_* post taks_math_2004_y*_g* _I* _g* enroll* if regular_hs == 1 & course_type == "math" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students students   using teachers_share_pooled, excel dec(3) nocons ctitle("Math, School FE, Control for Tracking")

	***ENGLISH --> STANFORD LANGUAGE***
	areg stanford_sd_lang_scale  post_share_students  share_students  stanf_lang_peer_*  post  stanf_lang_2004_y*_g* _I* _g* enroll* if regular_hs == 1 & course_type == "eng" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students students  using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, School FE, Control for Tracking")

	***SCIENCE  - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	areg  stanf_taks_sci  post_share_students  share_students stanf_science_peer_*   post stanf_science_2004_y*_g* _I* _g* enroll* if  regular_hs == 1  & course_type == "sci" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students students  using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, School FE, Control for Tracking")

	***SOC
	areg  stanf_taks_soc post_share_students  share_students stanf_socialstu_peer_*  post stanf_socialstu_2004_y*_g* _I* _g* enroll* if  regular_hs == 1  & course_type == "soc" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students  students using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, School FE, Control for Tracking")
	
	***MATH - STANF
	areg stanford_sd_math_scale post_share_students  share_students  stanf_math_peer_* _I* _g* enroll* stanf_math_2004_y*_g*  if regular_hs == 1 & course_type == "math" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students  students using teachers_share_pooled, excel dec(3) nocons ctitle("Math - Stanf, School FE, , Control for Tracking")

	
*CONTROL FOR IMMEDIATE LAG INSTEAD OF PRE-ASPIRE LAG
	use temp, clear
	xi i.grade*i.year, prefix(_g)
	xi i.female i.ethnicity i.econdis i.atrisk i.speced i.lep i.gifted 

	***MATH --> TAKS MATH
	areg taks_sd_scale_min_math post_share_students  share_students  post ltaks_sd_scale_min_math  _I* _g* enroll* if regular_hs == 1 & course_type == "math" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students students   using teachers_share_pooled, excel dec(3) nocons ctitle("Math, School FE, Control for Immediate Lag")

	***ENGLISH --> STANFORD LANGUAGE***
	areg stanford_sd_lang_scale  post_share_students  share_students  post  lstanford_sd_lang_scale _I* _g* enroll* if regular_hs == 1 & course_type == "eng" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students students  using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, School FE, Control for Immediate Lag")

	***SCIENCE  - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	areg  stanf_taks_sci  post_share_students  share_students  post lstanford_sd_science_scale _I* _g* enroll* if  regular_hs == 1  & course_type == "sci" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students students  using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, School FE, Control for Immediate Lag")

	***SOC
	areg  stanf_taks_soc post_share_students  share_students  post lstanford_sd_socialstu_scale _I* _g* enroll* if  regular_hs == 1  & course_type == "soc" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students  students using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, School FE, Control for Immediate Lag")
	
	***MATH - STANF
	areg stanford_sd_math_scale post_share_students  share_students post lstanford_sd_math_scale _I* _g* enroll*   if regular_hs == 1 & course_type == "math" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students  students using teachers_share_pooled, excel dec(3) nocons ctitle("Math - Stanf, School FE, , Control for Immediate Lag")

*/
	
**INSTRUMENT USING LAGGED SHARE FOR TEACHERS WHO CAN BE LINKED OVER TIME

	
	use temp, clear

	
	*CALCULATE SHARE FROM PRE 2004-05
	sort teacher_link_id grade course_type_a
	cap drop _merge
	merge m:1 teacher_link_id grade course_type_a using teacher_share_2004, keepusing(share_students_2004)
	gen post_share_students_2004 = post*share_students_2004

	keep if share_students_2004 != . & teacher_link_id != .
	
	
	xi i.grade*i.year, prefix(_g)
	xi i.female i.ethnicity i.econdis i.atrisk i.speced i.lep i.gifted 
	
	
	*FIRST TEST IF RESULTS ARE SIMILAR

	***MATH --> TAKS MATH
	areg taks_sd_scale_min_math post_share_students  share_students  post taks_math_2004_y*_g* _I* _g* enroll* if teacher_link_id != . & regular_hs == 1 & course_type == "math" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students students   using teachers_share_pooled, excel dec(3) nocons ctitle("Math, School FE, Teacher Link Subsample")

	***ENGLISH --> STANFORD LANGUAGE***
	areg stanford_sd_lang_scale  post_share_students  share_students   post  stanf_lang_2004_y*_g* _I* _g* enroll* if teacher_link_id != . &  regular_hs == 1 & course_type == "eng" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students students  using teachers_share_pooled, excel dec(3) nocons ctitle("Eng, School FE, Teacher Link Subsample")

	***SCIENCE  - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	areg  stanf_taks_sci  post_share_students  share_students  post stanf_science_2004_y*_g* _I* _g* enroll* if teacher_link_id != . &  regular_hs == 1  & course_type == "sci" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students students  using teachers_share_pooled, excel dec(3) nocons ctitle("Sci, School FE, Teacher Link Subsample")

	***SOC
	areg  stanf_taks_soc post_share_students  share_students post stanf_socialstu_2004_y*_g* _I* _g* enroll* if teacher_link_id != . &  regular_hs == 1  & course_type == "soc" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students  students using teachers_share_pooled, excel dec(3) nocons ctitle("Soc, School FE, Teacher Link Subsample")
	
	***MATH - STANF
	areg stanford_sd_math_scale post_share_students  share_students  post _I* _g* enroll* stanf_math_2004_y*_g*  if teacher_link_id != . &  regular_hs == 1 & course_type == "math" [pw = weight], cluster(campus) absorb(school_year)
	outreg2 post_share_students  share_students  students using teachers_share_pooled, excel dec(3) nocons ctitle("Math - Stanf, School FE, , Teacher Link Subsample")
	
	
	
	*2SLS W/ LAGGED SHARE
	xi i.campus, prefix(_c)

	***MATH --> TAKS MATH
	reg  post_share_students  share_students_2004 post_share_students_2004  post taks_math_2004_y*_g* _I* _g* _c* enroll* if teacher_link_id != . & regular_hs == 1 & course_type == "math" [pw = weight], cluster(campus)
	outreg2 share_students_2004 post_share_students_2004   using teachers_share_pooled, excel dec(3) nocons ctitle("Math, School FE, FS - Lag Share instrument")

	reg  share_students  share_students_2004 post_share_students_2004  post taks_math_2004_y*_g* _I* _g* _c* enroll* if teacher_link_id != . & regular_hs == 1 & course_type == "math" [pw = weight], cluster(campus)
	outreg2 share_students_2004 post_share_students_2004   using teachers_share_pooled, excel dec(3) nocons ctitle("Math, School FE, FS - Lag Share instrument")
	
	ivreg  stanford_sd_lang_scale (post_share_students share_students = post_share_students_2004 share_students_2004)  post taks_math_2004_y*_g* _I* _g* _c* enroll* if teacher_link_id != . & regular_hs == 1 & course_type == "math" [pw = weight], cluster(campus)
	outreg2 post_share_students share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Math, School FE, SS - Lag Share instrument")
	

	
	***ENGLISH --> STANFORD LANGUAGE***
	reg  post_share_students  share_students_2004 post_share_students_2004  post stanf_lang_2004_y*_g* _I* _g* _c* enroll* if teacher_link_id != . & regular_hs == 1 & course_type == "eng" [pw = weight], cluster(campus)
	outreg2 share_students_2004 post_share_students_2004   using teachers_share_pooled, excel dec(3) nocons ctitle("eng, School FE, FS - Lag Share instrument")

	reg  share_students  share_students_2004 post_share_students_2004  post stanf_lang_2004_y*_g* _I* _g* _c* enroll* if teacher_link_id != . & regular_hs == 1 & course_type == "eng" [pw = weight], cluster(campus)
	outreg2 share_students_2004 post_share_students_2004   using teachers_share_pooled, excel dec(3) nocons ctitle("eng, School FE, FS - Lag Share instrument")
	
	ivreg  stanford_sd_lang_scale (post_share_students share_students = post_share_students_2004 share_students_2004)  post stanf_lang_2004_y*_g* _I* _g* _c* enroll* if teacher_link_id != . & regular_hs == 1 & course_type == "eng" [pw = weight], cluster(campus)
	outreg2 post_share_students share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("eng, School FE, SS - Lag Share instrument")
	

	
	***SCIENCE  - CONTROL FOR LAGGED STANFORD INSTEAD OF TAKS AS LAGGED TAKS IS NOT AVAILABLE FOR MANY 10TH GRADERS	
	reg  post_share_students  share_students_2004 post_share_students_2004  post stanf_science_2004_y*_g* _I* _g* _c* enroll* if teacher_link_id != . & regular_hs == 1 & course_type == "sci" [pw = weight], cluster(campus)
	outreg2 share_students_2004 post_share_students_2004   using teachers_share_pooled, excel dec(3) nocons ctitle("sci, School FE, FS - Lag Share instrument")

	reg  share_students  share_students_2004 post_share_students_2004  post stanf_science_2004_y*_g* _I* _g* _c* enroll* if teacher_link_id != . & regular_hs == 1 & course_type == "sci" [pw = weight], cluster(campus)
	outreg2 share_students_2004 post_share_students_2004   using teachers_share_pooled, excel dec(3) nocons ctitle("sci, School FE, FS - Lag Share instrument")
	
	ivreg  stanf_taks_sci (post_share_students share_students = post_share_students_2004 share_students_2004)  post stanf_science_2004_y*_g* _I* _g* _c* enroll* if teacher_link_id != . & regular_hs == 1 & course_type == "sci" [pw = weight], cluster(campus)
	outreg2 post_share_students share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("sci, School FE, SS - Lag Share instrument")

	
	***SOC
	reg  post_share_students  share_students_2004 post_share_students_2004  post stanf_socialstu_2004_y*_g* _I* _g* _c* enroll* if teacher_link_id != . & regular_hs == 1 & course_type == "soc" [pw = weight], cluster(campus)
	outreg2 share_students_2004 post_share_students_2004   using teachers_share_pooled, excel dec(3) nocons ctitle("soc, School FE, FS - Lag Share instrument")

	reg  share_students  share_students_2004 post_share_students_2004  post stanf_socialstu_2004_y*_g* _I* _g* _c* enroll* if teacher_link_id != . & regular_hs == 1 & course_type == "soc" [pw = weight], cluster(campus)
	outreg2 share_students_2004 post_share_students_2004   using teachers_share_pooled, excel dec(3) nocons ctitle("soc, School FE, FS - Lag Share instrument")
	
	ivreg  stanf_taks_soc (post_share_students share_students = post_share_students_2004 share_students_2004)  post stanf_socialstu_2004_y*_g* _I* _g* _c* enroll* if teacher_link_id != . & regular_hs == 1 & course_type == "soc" [pw = weight], cluster(campus)
	outreg2 post_share_students share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("soc, School FE, SS - Lag Share instrument")
	

	
	***MATH - STANF
	reg  post_share_students  share_students_2004 post_share_students_2004  post stanf_math_2004_y*_g* _I* _g* _c* enroll* if teacher_link_id != . & regular_hs == 1 & course_type == "math" [pw = weight], cluster(campus)
	outreg2 share_students_2004 post_share_students_2004   using teachers_share_pooled, excel dec(3) nocons ctitle("Math - Stanf, School FE, FS - Lag Share instrument")

	reg  share_students  share_students_2004 post_share_students_2004  post stanf_math_2004_y*_g* _I* _g* _c* enroll* if teacher_link_id != . & regular_hs == 1 & course_type == "math" [pw = weight], cluster(campus)
	outreg2 share_students_2004 post_share_students_2004   using teachers_share_pooled, excel dec(3) nocons ctitle("Math - Stanf, School FE, FS - Lag Share instrument")
	
	ivreg  stanford_sd_math_scale (post_share_students share_students = post_share_students_2004 share_students_2004)  post stanf_math_2004_y*_g* _I* _g* _c* enroll* if teacher_link_id != . & regular_hs == 1 & course_type == "math" [pw = weight], cluster(campus)
	outreg2 post_share_students share_students   using teachers_share_pooled, excel dec(3) nocons ctitle("Math - Stanf, School FE, SS - Lag Share instrument")
	

	
	
